Solved

Skip a cell on TAB in datagridview

Posted on 2006-10-29
5
2,775 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

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

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

15 Experts available now in Live!

Get 1:1 Help Now