[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3346
  • Last Modified:

Skip a cell on TAB in datagridview

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
alungwyther
Asked:
alungwyther
1 Solution
 
newyuppieCommented:
try setting the StandardTab property of the Datagridview to TRUE (and remove the manual key processing)
0
 
alungwytherAuthor Commented:
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
 
gangwischCommented:
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
 
SanclerCommented:
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
 
alungwytherAuthor Commented:
Hi Roger

Many thanks, that did the trick.

Alun
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now