HOWTO: Select and Unselect a Range of Cells in MSFlexGrid
ID: Q187834
|
The information in this article applies to:
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0
SUMMARY
This article demonstrates how to select a range of cells and how to
unselect a range of selected cells using the MSFlexGrid control.
MORE INFORMATION
The Visual Basic documentation provides a good explanation in the Online
Help of how to select a range of cells in a MSFlexgrid control. However,
there is no such explanation for how to undo a selection that has already
been made. The example below demonstrates both.
Step-by-Step Example
- Start a new Standard EXE project. Form1 is created by default.
- Click Components on the Project menu, check "Microsoft FlexGrid
Control," and then click OK.
- Add a MSFlexGrid control to Form1.
- Add two CommandButtons to Form1.
- Change the Caption property of Command1 to "UnSelect."
- Change the Caption property of Command2 to "Select."
- Add the following code to the module of Form1:
Private Sub Command1_Click()
' unselect a range
With MSFlexGrid1
' cancel selection by setting end points to start points
.RowSel = .Row
.ColSel = .Col
.SetFocus
End With
End Sub
Private Sub Command2_Click()
' select a range
With MSFlexGrid1
' Row and Col properties must be set before RowSel and ColSel
.Col = 0 ' start selection in this column
.Row = 2 ' start selection in this row
.ColSel = 1 ' end selection in this column
.RowSel = 4 ' end selection in this row
.SetFocus
End With
End Sub
Private Sub Form_Load()
With MSFlexGrid1
.Clear
.FixedCols = 0
.FixedRows = 0
.AddItem "mike" & vbTab & 10, 0
.AddItem "fred" & vbTab & 11, 1
.AddItem "jack" & vbTab & 13, 2
.AddItem "herman" & vbTab & 55, 3
.AddItem "irene" & vbTab & 88, 4
.AddItem "jane" & vbTab & 22, 5
End With
End Sub
- Press the F5 key to run the project. Click on the "Select" button. You
should see the middle of the MSFlexGrid selected.
- Click on the "UnSelect" button, and note that the selection is undone.
Additional query words:
kbDSupport kbDSD flex grid kbVBp kbVBp500 kbCtrl kbVBp600
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbhowto
|