Question how to obtain values from datagrid and display it in new form

mhabhelle14

New member
Joined
May 5, 2008
Messages
1
Programming Experience
Beginner
Hi,

I am developing window based forms connecting with sql server database. I need to capture double click events
for a datagrid and show the value of selected row in the textbox in a new form. Could someone please help me on this.

I am using VB.NET 2003 and sql server

Please reply.

Cheers,
mhabhelle14
 
Please don't make 4 threads for the same topic. I deleted the 3 in the data access sections and moved the vb.net general thread to this winforms section.
 
I think there is a "CurrentCellAddress" (or something like that) property that gives a Point struct that represents the location of the current cell. Just use the Y property of that Point to tell which record to show.

The DataGridView's DataSource property should be a DataView or DataTable (in which case it's using the DataTable's default view). Use that DataView's indexer property to access the DataRowView you need to show "myDataView(myGrid.CurrentCellAddress.Y)". If you use a typed DataSet, you can get the typed DataRow from the DataRowView (I think the property's name is "Row").

You will have to do a few casts here and there. If you're using this Form as a dialog and you get or set the selected position before it is first shown, you may find a few nulls (Nothing) and maybe a Y position of -1 on the way. Just make sure you check everything correctly.

Btw, I think ppl usually use a BindingSource for that... I just never did that myself because I didn't see the point for the overhead but it probably gives less code. You cast "myBinder.Current" to DataRowView and go from there.
 
Last edited:
Back
Top