Solved

Skip a cell on TAB in datagridview

Posted on 2006-10-29
5
2,834 Views
Last Modified: 2008-03-03
Hi

I need to skip a cell, that is read only, when the user presses the Tab key.
I have tried the following code to skip over column 2

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

        Select Case keyData
            Case Keys.Tab
                If grdHSE.CurrentCell.ColumnIndex = 1 Then
                    grdHSE.CurrentCell = grdHSE(3, grdHSE.CurrentCell.RowIndex)
                End If
        End Select
    End Function

but it skips to column 4 not 3.

All help much appreciated.

Best Regards
Alun Gwyther
0
Comment
Question by:alungwyther
5 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17828668
try setting the StandardTab property of the Datagridview to TRUE (and remove the manual key processing)
0
 

Author Comment

by:alungwyther
ID: 17828681
Hi

Thanks for the reply.

If I do that then the focus goes to the next control in the tab order on the form.

Best Regards
Alun Gwyther
0
 
LVL 10

Expert Comment

by:gangwisch
ID: 17829076
what i normally do is onkeypress
if e.keycode=tab then
sendkeys.send("{RIGHT}")
end if

this gets me to where i want to be
0
 
LVL 34

Accepted Solution

by:
Sancler earned 250 total points
ID: 17829369
What I think is happening here is that the CurrentCell is being changed to grdHSE(3, grdHSE.CurrentCell.RowIndex) BEFORE the Tab keystroke is firing, so that when it does fire, it is then moving the focus to the next cell, which is grdHSE(4, grdHSE.CurrentCell.RowIndex).  What you need to do is consume the Tab keystroke, so that it doesn't get processed after you have set the cell you want.  LIke this

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Debug.WriteLine(grdHSE.CurrentCell.RowIndex)
        Select Case keyData
            Case Keys.Tab
                If grdHSE.CurrentCell.ColumnIndex = 1 Then
                    grdHSE.CurrentCell = grdHSE(3, grdHSE.CurrentCell.RowIndex)
                    Return True '<<< NOTE NEW LINE
                End If
        End Select
    End Function

Roger
0
 

Author Comment

by:alungwyther
ID: 17831331
Hi Roger

Many thanks, that did the trick.

Alun
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
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…

776 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