Saturday, November 15, 2008

DATAGRIDVIEW MOVEMENT THROUGH COLUMN WHEN PRESSING ENTER KEY



USING VB .NET

'Declare row,col as public

Dim row, col As Integer


'Write the below code in CellEndEdit Event

Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit

row = e.RowIndex
col = e.ColumnIndex

End Sub


'Write the below code in DataGridView SelectionChanged Event [ SAY DATAGRIDVIEW HAS 4 COLUMNS ]

Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged

Try
Dim sl As Integer
sl = row

If DataGridView1.Rows.Count > 1 Then

Select Case col

Case 0, 1, 2

DataGridView1.CurrentCell = Me.DataGridView1(col + 1, row)

Case 3

DataGridView1.CurrentCell = Me.DataGridView1(0, row + 1)

End Select

End If


Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub


Click here for coverting VB .NET to C#.NET and viseversa

No comments: