Solved

Skip a cell on TAB in datagridview

Posted on 2006-10-29
5
2,928 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net WebRequest Code from JSON curl 7 94
Expression Evaluater 3 46
Visual studio 2015 1 35
SQL Session Remains Open After ReportViewerControl Form is Closed. 8 36
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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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