Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net how to navigate column wise in DataGridView

Status
Not open for further replies.

nbhatti

Programmer
Joined
Sep 23, 2008
Messages
4
Location
PK
m using DataGridView for data entering. i want to shift on next cell on clicking on enter key. by default it is shifting to next row in same column. but i want to shift on next column, and if the focus on last column then it should focus on next column's first cell
 
On the KeyUp event of the datagrid see if the key was the Enter key, and if so, move wherever you want.

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
is there any default convention to move the cursor in grid. like we can change in excel. we can't change it to column wise, rather then row wise
 
I got this code from the developer team.

Code:
Public Class dgIsian

    'this tells this class that is a datagridview
    Inherits System.Windows.Forms.DataGridView

    'this function do the half of job 
    'when you hit a key (like return) it transforms like you 
    'have been hit the tab key
    'this doent work when you are editing the cell

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

        If keyData = Keys.Return Then
            keyData = Keys.Tab
            With msg
                .WParam = Keys.Tab
            End With
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

    'this second function works when you are editing the cell
    'does the same as the function above changing return for tab
    Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
		If keyData = Keys.Return Then
			keyData = Keys.Tab
		End If

        Return MyBase.ProcessDialogKey(keyData)
    End Function

End Class

Have fun.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top