How To Select and Unselect a Range of Cells in MSFlexGrid

Article translations Article translations
Article ID: 187834 - View products that this article applies to.
This article was previously published under Q187834
Expand all | Collapse all

On This Page

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

  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.

Properties

Article ID: 187834 - Last Review: July 13, 2004 - Revision: 1.2
APPLIES TO
  • 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
Keywords: 
kbhowto KB187834

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com