Groups | Blog | Home
all groups > vb.net controls > november 2006 >

vb.net controls : using ENTER key to move to the right cell datagridview


BisterBooster
11/12/2006 7:52:41 PM
Hi,

Can someone help me for next problem
How to for using ENTER key to move to the right cell instead of the TAB key


Many thanks in advance
Marc.










Michel Posseth [MCP]
11/12/2006 8:23:02 PM
Well ,,,

This would do the trick :
you could just set the keypreview property of the form to true and thus
catch the enter key and send a tab with the sendkeys method

regards

michel posseth [MCP]

"BisterBooster" <koekoek@Nomail.be> schreef in bericht
news:eqHZ9zoBHHA.4844@TK2MSFTNGP02.phx.gbl...
[quoted text, click to view]

james
12/20/2006 10:14:45 PM
hi Marc,

use this code

------------------------------------------------------------------------------
Private Sub DataGridView1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
If DataGridView1.CurrentCell.ColumnIndex = DataGridView1.ColumnCount - 1 Then
If DataGridView1.CurrentCell.RowIndex < DataGridView1.RowCount - 1 Then
DataGridView1.CurrentCell = DataGridView1.Item(0, DataGridView1.CurrentCell.RowIndex + 1)
End If
Else
DataGridView1.CurrentCell = DataGridView1.Item(DataGridView1.CurrentCell.ColumnIndex + 1, DataGridView1.CurrentCell.RowIndex)
End If
End If
e.Handled = True
End Sub

Dim LastEditedCell As DataGridViewCell

Sub getLastCell()
Try
Dim r, c As Short
r = LastEditedCell.RowIndex
c = LastEditedCell.ColumnIndex
LastEditedCell = Nothing
DataGridView1.CurrentCell = Me.DataGridView1.Rows(r).Cells(c + 1)
Catch Ex As Exception
MsgBox(Ex.Message)
End Try
End Sub

Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
LastEditedCell = DataGridView1.CurrentCell
End Sub

Private Sub DataGridView1_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
If Not LastEditedCell Is Nothing Then
If (DataGridView1.CurrentCell.RowIndex = LastEditedCell.RowIndex + 1) And (DataGridView1.CurrentCell.ColumnIndex = LastEditedCell.ColumnIndex) Then
System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = False
Dim subThread As New Threading.Thread(AddressOf getLastCell)
subThread.Start()
End If
End If
End Sub


------------------------------------------------------------------------------
Regards,
James fredric.

[quoted text, click to view]

Can someone help me for next problem
How to for using ENTER key to move to the right cell instead of the TAB key


Many thanks in advance
Marc.













___
AddThis Social Bookmark Button