We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Retrieving a row value on double Click of a Datagrid

I had created a datagrid and bound it with a table in runtime. Now i need to know how can i retrieve the current row value when a user double clicks the datagrid. There is only one column displayed in my datagrid. thanks in advance srini

2 Replies

JO John April 7, 2004 12:54 AM UTC

Try this. ' Create the event handle for the double click Private Sub DataGrid1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick ' get the current row from the Binding Manager Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember) Dim drTemp As DataRow = CType(bm.Current, DataRowView).Row ' you can then retrieve any column's value from the drTemp Msgbox(drTemp(0).Tostring) End Sub > I had created a datagrid and bound it with a table in runtime. Now i need to know how can i retrieve the current row value when a user double clicks the datagrid. > > There is only one column displayed in my datagrid. > > thanks in advance > srini > >


AN Anonymous June 4, 2004 09:42 AM UTC

I am having a problem with this solution, which is similar to FAQ 5.74. My DataGrid (.NET 2003, 1.1) does not have a BindingContext property. There is a similar reference in MS KB Q308070. It might indeed work if I had that property...but is this protected so that I have to expose via a custom class? Other MS documentation discusses using the CurrencyManager object for each grid (I have 3 on one form.) But it appears that you have to manually update the CurrencyManager when a column sort occurs? Any help greatly appreciated. > Try this. > > ' Create the event handle for the double click > > Private Sub DataGrid1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick > > ' get the current row from the Binding Manager > Dim bm As BindingManagerBase = Me.DataGrid1.BindingContext(Me.DataGrid1.DataSource, Me.DataGrid1.DataMember) > > Dim drTemp As DataRow = CType(bm.Current, DataRowView).Row > > ' you can then retrieve any column's value from the drTemp > > Msgbox(drTemp(0).Tostring) > > End Sub > > > > > > I had created a datagrid and bound it with a table in runtime. Now i need to know how can i retrieve the current row value when a user double clicks the datagrid. > > > > There is only one column displayed in my datagrid. > > > > thanks in advance > > srini > > > > >

Loader.
Live Chat Icon For mobile
Up arrow icon