Home All Groups Group Topic Archive Search About

Datagridview - Move Focus to a Particular Cell

Author
26 Jul 2006 10:19 AM
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?

Author
26 Jul 2006 10:59 AM
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?
Found it!
DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.NewRowIndex)
Author
26 Jul 2006 11:00 AM
Ken Tucker [MVP]
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
--------------------
Show quoteHide quote
"Paul Remblance" <p***@remblance.co.uk> wrote in message
news:4iotp5F4q62nU1@individual.net...
>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?
>