Solved

Datagridview move cursor to right

Posted on 2014-10-05
1
162 Views
Last Modified: 2014-10-05
Hi Experts
I have a datagridview and the focus moves to next row down  line when Enter Key pressed.
but I would like to move to next cell to the right  on the same row.

Please help
0
Comment
Question by:b001
1 Comment
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
ID: 40362186
Hello,

taken from http://stackoverflow.com/questions/18505431/how-to-move-to-another-column-in-datagridview-using-enter-in-vb-net

here is the code:
 
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
            If e.KeyCode = Keys.Enter Then
                e.SuppressKeyPress = True
                Dim iCol = DataGridView1.CurrentCell.ColumnIndex
                Dim iRow = DataGridView1.CurrentCell.RowIndex
                If iCol = DataGridView1.Columns.Count - 1 Then
                    If iRow < DataGridView1.Rows.Count - 1 Then
                        DataGridView1.CurrentCell = DataGridView1(0, iRow + 1)
                    End If
                Else
                    DataGridView1.CurrentCell = DataGridView1(iCol + 1, iRow)
                End If
            End If
        End Sub

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now