Solved

Datagridview move cursor to right

Posted on 2014-10-17
4
115 Views
Last Modified: 2014-10-24
Hi
I am trying to move the cursor to right in the grid when ENTER key is pressed.
My Code
 
Private Sub DataGridParts_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridParts.KeyDown

        If e.KeyCode = Keys.Enter Then
         
                e.SuppressKeyPress = True
                Dim iCol = DataGridParts.CurrentCell.ColumnIndex
                Dim iRow = DataGridParts.CurrentCell.RowIndex
            If iCol = 9 Then
                        DataGridParts.CurrentCell = DataGridParts(0, iRow + 1)
                    Else
                        DataGridParts.CurrentCell = DataGridParts(iCol+1, iRow)
              End If
       
     end if
end sub
It works fine as long as you don not change any cell value.
If I change the cell text and then when ENTER key pressed it goes down to next row instead going to right in the sale row.

Please help
0
Comment
Question by:b001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:louisfr
ID: 40387237
Use the PreviewKeyDown event to tell the control Enter must be processed as an input key:
private void DataGridParts_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    switch (e.KeyCode)
    {
        case Keys.Enter:
            e.IsInputKey = true;
            break;
    }
}

Open in new window

0
 

Author Comment

by:b001
ID: 40388048
Hi losisfr

please convert the above code for  VB Basic
Thanks
0
 

Author Comment

by:b001
ID: 40388049
I mean Visual Studio Basic
0
 
LVL 11

Accepted Solution

by:
louisfr earned 500 total points
ID: 40388987
Sorry, here:
Private Sub DataGridParts_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs) Handles DataGridParts.PreviewKeyDown
    Select case e.KeyCode
        Case Keys.Enter
            e.IsInputKey = true
    End Select
End Sub

Open in new window

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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