?
Solved

Datagridview move cursor to right

Posted on 2014-10-17
4
Medium Priority
?
118 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 2000 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 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