You are currently offline, waiting for your internet to reconnect

How To Select and Unselect a Range of Cells in MSFlexGrid

This article was previously published under Q187834
This article has been archived. It is offered "as is" and will no longer be updated.
This article demonstrates how to select a range of cells and how tounselect a range of selected cells using the MSFlexGrid control.
The Visual Basic documentation provides a good explanation in the OnlineHelp 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 alreadybeen made. The example below demonstrates both.

Step-by-Step Example

  1. Start a new Standard EXE project. Form1 is created by default.
  2. Click Components on the Project menu, check "Microsoft FlexGrid Control," and then click OK.
  3. Add a MSFlexGrid control to Form1.
  4. Add two CommandButtons to Form1.
  5. Change the Caption property of Command1 to "UnSelect."
  6. Change the Caption property of Command2 to "Select."
  7. 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						
  8. Press the F5 key to run the project. Click on the "Select" button. You should see the middle of the MSFlexGrid selected.
  9. Click on the "UnSelect" button, and note that the selection is undone.
kbDSupport kbDSD flex grid kbVBp kbVBp500 kbCtrl kbVBp600

Article ID: 187834 - Last Review: 12/05/2015 08:48:34 - Revision: 1.2

Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic 6.0 Enterprise Edition

  • kbnosurvey kbarchive kbhowto KB187834