Referencing the selected ro in a DataGrid
-
On my windows form I have a textbox and a datagrid. As I navigate through the grid's data how can I display the selected row of the first column in the textbox? Thanks
There are many ways to extract information, first you need to identify the index of the record you want to extract. We can use the ME.Databindingcontext( datasource ).position to identify the current row. Normally we assign a table to a datagrid's datasource, but here we will use the Table.Defaultview. SO given TBL1 as your datatable Datagrid.datasource = TBL1.Defaultview then we can use Me.BindingContext(TBL1.DefaultView).Position() to indentify the current row, this should work even it you change the sort field of the datagrid. I think thats it. Dim ID As String 'use the this event handle Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged Dim x As Int16 'Datagrid1.datsource = tbl1.Defaultview ' instead of Datagrid1.datsource = tbl1 ' you must explicitly point to the tables defaultview 'Get the position of the Table's Defaultview x = Me.BindingContext(TBL1.DefaultView).Position() 'use x to identify you row textbox1.text = TBL1.DefaultView(x)("fieldname") End Sub Marvin N. Guerrero - Taje Kage_bunshinNunJutsU Marvin N. Guerrero - Taje Kage_bunshinNunJutsU
-
On my windows form I have a textbox and a datagrid. As I navigate through the grid's data how can I display the selected row of the first column in the textbox? Thanks
-
hi, try this TxtboxName.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex(), 0).ToString() Live Life King Size Asif