Title | Use code to select rows and columns in a DBGrid control |
Keywords | DbGrid, select row, select column |
Categories | Controls |
|
|
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.
|
|
|
|