Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row selection problem with TDBGrid

Status
Not open for further replies.

RZillmer

Programmer
Nov 20, 2001
42
US
I have a TDBGrid with the MultiSelect property set to Extended. It behaves as I would expect: clicking a row selects it, ctrl-clicking a row adds it to the current selection of rows, shift-clicking selects all rows between the clicked row and previously selected row.

So far, so good.

I have a button on my form for selecting all rows. Here is the code:

Code:
Private Sub CmdAll_Click()

On Error GoTo CmdAll_Click_Error
 
    ' clear all the current selected row bookmarks
    While calibrationChoicesGrid.SelBookmarks.Count <> 0
        calibrationChoicesGrid.SelBookmarks.Remove (0)
    Wend
    
    ' add a selected row bookmark for every row in the grid
    calibrationChoicesGrid.MoveFirst
    
    While Not calibrationChoicesGrid.EOF
        calibrationChoicesGrid.SelBookmarks.Add (calibrationChoicesGrid.Bookmark)
        calibrationChoicesGrid.MoveNext
    Wend
    
    ' update the label displaying the number of records selected
    calibrationChoicesGrid_SelChange (0)
 
CmdAll_Click_Exit:
    Exit Sub
CmdAll_Click_Error:
    Call Log_Errors(Err.Number, Err.description, Erl, "frmPriceList-CmdAll_Click")
    Resume CmdAll_Click_Exit

End Sub

NOTE: calibrationChoicesGrid_SelChange does nothing except update the values of various controls dealing with the number of records selected. It's not the cause of my problems (I've checked).

This code works perfectly, except for if the user decides not to leave all rows selected. Clicking on a row deselects all rows and selects the clicked row, ctrl-clicking then adds the clicked row to the selected rows, but shift-clicking deselects all rows. Shift-click has this behavior until I refresh the data on which the grid is based. It then goes back to working normally.

Is this an error in my code or a bug in VB? Can anyone else reproduce this or tell me how to fix it? Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top