[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

DB Grid Basic question

I have a DBGrid, very basic question.

When using the tab to move between columns, I have to press tab twice if entering a new Value.  The first time appears to set the value into the column and the next tab moves me to the next column.  Is there a way around this?

Also, When reaching the last column, is it wise to immediately start a new row.  Or is it more work than it's worth.  Currently, upon leaving the last column in the new row, the focus switches to my exit button.

1 Solution
Okay... I'm going to attempt to answer your question, though I don't actually use the VB version of DBGrid.

The code below should take care of your problem with needed to press <TAB> twice:

Private Sub DBGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    Static blnRecursive As Boolean

    If blnRecursive = False Then
        If KeyCode = 9 Then
            If DBGrid1.CurrentCellModified = True Then
                blnRecursive = True
                KeyCode = 0
                SendKeys "{TAB}{TAB}"
                blnRecursive = False
            End If
        End If
    End If
End Sub

In response to starting a new row when tabbing past the last column, my response would be "yes" - maybe.  It really depends upon what you are doing.  If you allow your end user to actually create a new record, by all means.  If it won't offend your software's standards, I find that the functionality is great.  Nothing is worse in data entry than to have to stop and use your mouse to do something.

In order to tab straight to a new row upon leaving the last row, make sure you set your WrapCellPointer property to True, and make sure that the TabAction property is set to 2 - Grid Navigation.

Hopefully this helped a little.
Once in a column/cell you can actually start typing the new value, pressing <Enter> to accept the value & then <tab> to move to next.  

To go to the next row at end of columns, it is simply a couple of dbgrdnavigation settings in the grid property.  I've found it is simply an end-user preference that determines which way I set it.

Hope this helps,

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

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