How to check whether user selected row in datagrid view and this row is not newrow?
I tried so far this but not working as should:
If Not IsNothing(Grid.CurrentRow) And Not Grid.CurrentRow.IsNewRow Then
If you have selected new row, the
DataGridView will changes the current row on its
OnValidating method. So if you click on
Button when you have selected new row, the row remains selected, but the current row will be changed to its previous row.
So instead of checking for current row, if you want to do this check in
Click event of a
Button, it's better check for
if (dataGridView1.SelectedRows.Count == 1 && dataGridView1.SelectedRows.Index == dataGridView1.NewRowIndex) MessageBox.Show("New Row Selected");
If (DataGridView1.SelectedRows.Count = 1 AndAlso _ DataGridView1.SelectedRows(0).Index = DataGridView1.NewRowIndex) Then MessageBox.Show("New Row Selected") End If
Note: Your provided code in question, will work untill the control is focuded.