Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleUse code to select rows and columns in a DBGrid control
KeywordsDbGrid, select row, select column
CategoriesControls
 
To select columns, use the control's SelStartCol and SelEndCol properties. To deselect columns, call the control's ClearSelCols method.
 
Private Sub cmdSelectColumn_Click()
    DBGrid1.SelStartCol = 1
    DBGrid1.SelEndCol = 1
End Sub

Private Sub cmdDeselectColumn_Click()
    DBGrid1.ClearSelCols
End Sub
 
To select rows, add the rows' RowBookmark value to the control's SelBookmarks collection. To deselect a row, remove its bookmark from the collection.
 
Private Sub cmdSelectRows_Click()
Dim i As Integer
Dim max_row As Integer

    max_row = DBGrid1.VisibleRows - 1
    For i = max_row * 0.25 To max_row * 0.75
        DBGrid1.SelBookmarks.Add DBGrid1.RowBookmark(i)
    Next i
End Sub

Private Sub cmdDeselectRows_Click()
    With DBGrid1.SelBookmarks
        Do While .Count > 0
            .Remove 0
        Loop
    End With
End Sub
 
Note that row and column selections are independent so deselecting a row does not deselect a cell that lies in a selected column and vice versa.
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated