Newbie question.
I have DataGridView that has a list of records.
I want to double click on one row and bring up a NEW form with a detailed edit form for that record.
1) How assign a KEY to the DataGridView
2) How to I access the key and pass it do the new form
3) How do I create all this on a row double click (not cell double click)
Thanks.

How do I create a GridView/edit screen?
Paul_siq
Yea thats not a bad idea you can call that value all over your application. Good Luck
-Senthil
André Phillip
OK now I have understand clearly what you meant by the Key well the easiest and the simplest way is to populate the grid along with the key and make the key column visible property to False.Even though the visible property is set to false still you can able to get the Key value from the grid.
-Senthil
duderino
Thanks. A couple of follow ups.
1) Does that mean you must include your key field as a cell in the datagridview What if you do not want it in there I.e., in ASP.NET, you can assign a 'DataKey' property to a Grid.
2) When moving from form to form, would it also be acceptable to pass a parameter to the new form frmo the old form
Form2 f = new Form2(this.keyField);
f.Show();
Where Form2's default constructor accepts a keyField.
Is that a good practice for some forms that load a record every time they are instantiated, that they accept a key field to load their data
Thanks.
Mike14598
Any objections to using a global static field in the Program class to use as a global variable
Rather than pass values from one form to the other, I have just created a static field.
Thanks again for your help.
crjangel
you can do it by the following
I have answered based on your question number
1. Key = DataGridView.CurrentRow.Cells(columnindex/name).value
2.You can declare the Key as public in your Form1 and call it in Form2
in Form1
Public Key as string/anydatatype
in Form2
Dim Key as string/anydatatype
Key = My.Forms.Form1.Key
3. You can use DataGridView.RowHeaderMouseDoubleClick event which will fire when the user double clicks the datagridview row.
Hope this helps
-Senthil
obixena
Oops I might have understand your first question wrongly I am thinking may be the Key what you have mentioned is to know which row the user has clicked if in that case you can get the rowindex of the datagrid view.
Key = Datagridview.Currentrow.index
You can use the rowindex to get the values of the Datagridview in to the otheform.
-Senthil
RMKelley
But the current row index is just the number of the row. It does not necessarily mean the key field of that row.
If I have an Order summary screen that has OrderNum as a key field, I want to drill down to the order detail. The order number may be 12345, but the row index may be '5' if it is the 5th row. What I need is the 12345 part.
Also, I may not want to actually include the 12345 in my DataGridView output. This may not have any meaning to an end user.
Thanks.