Reputation:
I don't know how to set focus point always to the new row in DataGridView in the beginning??
Upvotes: 6
Views: 73039
Reputation: 39
dgvSimpleReports.Rows(dgvSimpleReports.Rows.Count - 1).Selected = True
dgvSimpleReports.CurrentCell = dgvSimpleReports.Rows(dgvSimpleReports.Rows.Count - 1).Cells(0)
Selected is not enough, because selected row only selects the row but DataGridView is not focused automatically. You need to set current row , but current row is ReadOnly, so you need to use current cell, because current cell is not ReadOnly, the code stated below should fix this problem.
Upvotes: 4
Reputation: 1
To focus on the newly added row :-
dataGridView1.Rows(dataGridView1.Rows.Count - 1).Selected = true;
or you can use this to focus on userdefine row
dataGridView1.Rows(Rowindex).Selected = true;
Ensure just the last full row is selected by using the following in your init code:
dataGriView1.MultiSelect = False
dataGriView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Keep Coding
Upvotes: 12
Reputation: 51
dim NoRow As Integer = 2
me.gridTickets.CurrentCell = me.gridTickets.Rows(NoRow).Cells(0)
Upvotes: 5
Reputation: 11
If (DgViewCityMaster.Rows.Count > 0) Then
DgViewCityMaster.Rows(0).Selected = True
End If
' Here DGViewCityMaster is my Data Grid View
Upvotes: 1
Reputation: 82136
You want to handle the RowsAdded event of your DataGridView and just select the newly added row.
Private Sub MyDataGridView_RowsAdded(ByVal sender As Object, ByVal e As DataGridViewRowsAddedEventArgs) Handles MyDataGridView.RowsAdded
MyDataGridView.Rows(e.RowIndex).Selected = true;
End Sub
Upvotes: 0