[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Skip a cell on TAB in datagridview

Posted on 2006-10-29
5
Medium Priority
?
3,238 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

872 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