hello
i have a datagridview (Dg) with 7 columns.
i have a RowValidated event which tests if the validated cell is the first (index = 0)
then sets the focus on the third cell with columnIndex = 2
BUT the cell that's getting focus after the row is validated is on the next row not the row that's has been validated !!
Private Sub Dg_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Dg.RowValidated
Dim colIndex = e.ColumnIndex
Dim RowIndex = e.RowIndex
If colIndex = 0 Then
AjoutTableAdapter.Fill(ProductsDataSet.products)
Dim Data = AjoutTableAdapter.GetData()
Dim Row = Data.Select("code='" & Dg(colIndex, RowIndex).Value & "'")
Dim rw = Dg.Rows(RowIndex)
Dg(1, RowIndex).Value = Row(0)("name")
Dg(3, RowIndex).Value = Row(0)("price")
Dg.CurrentCell = Dg(2, RowIndex)
End If
End Sub
here's a more generic code with no database etc
Private Sub Dg_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
Dim colIndex = e.ColumnIndex
Dim RowIndex = e.RowIndex
If colIndex = 0 Then
Dim rw = Dg.Rows(RowIndex)
Dg(1, RowIndex).Value = "Name Example"
Dg(3, RowIndex).Value = "10 $"
Dg.CurrentCell = Dg(2, RowIndex)
End If
End Sub
this is a screenshot:
and thanks for your time !!