Can anyone tell me how to read the current selected row/column number of a DaraGridView (in C#). I thought this would be simple like some other controls like listboxes, but it has given me a bit of grief!
I have disabled the multiple selection property on my DataGridView, so only one row can ever be the selected row.
Try this: [ assuming "view" is a DataGridView ]
selectedRowNumber = view.SelectedRows.Count > 0 ? view.SelectedRows : -1;
If you know that only one row can be selected, the 0 index of the selectedrows should return it. If there are no selected rows, it returns -1.
well, if you have selected selectionmode=FullRowSelect in the properties of the datagrid view and multiselect = false maybe this code work for you, and give you the oportunity of make the changes when the user move in the datagridview control.
Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
ID_Sel.Text = DataGridView1.Rows(e.RowIndex).Cells("ID").Value