Solved

Datagridview move cursor to right

Posted on 2014-10-17
4
108 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

21 Experts available now in Live!

Get 1:1 Help Now