Datagridview - Move Focus to a Particular Cell

  • Thread starter Thread starter Paul Remblance
  • Start date Start date
P

Paul Remblance

I am trying to use the bindingnavigator addnewitem button to place the focus
on the first cell in the newrow row. I have disabled the default action and
I am using the bindingnavigatoraddnewitem click event. Using newrowindex for
the row how can I move the focus?
 
I am trying to use the bindingnavigator addnewitem button to place the
focus on the first cell in the newrow row. I have disabled the default
action and I am using the bindingnavigatoraddnewitem click event. Using
newrowindex for the row how can I move the focus?
Found it!
DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.NewRowIndex)
 
Hi,

Here is an example. I added a bindingnaviagator and datagridview to a
form.

Public Class Form1
Dim bs As New BindingSource

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String = _
"Server = .;Database = NorthWind;" & _
"Integrated Security = SSPI;"
Dim conn As New SqlClient.SqlConnection(strConn)
Dim dt1 As New DataTable
Dim da1 As New SqlClient.SqlDataAdapter _
("Select * from Orders", conn)
da1.Fill(dt1)
bs.DataSource = dt1
DataGridView1.DataSource = bs
BindingNavigator1.BindingSource = bs
End Sub

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
BindingNavigatorAddNewItem.Click
bs.AddNew()
bs.Position = bs.Count
End Sub
End Class

Ken
 
Back
Top