Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a FlexGrid's selected rows more distinctive
Keywordsdistinctive, FlexGrid, rows
CategoriesControls
 
If you set a FlexGrid's SelectionMode property to flexSelectionByRow, the entire row is selected when the user clicks on any cell in it.

Normally the cells in the row are colored, except for the leftmost cell. To color the entire row, create a hidden column at the beginning and set its width to zero. The user sees the other cells colored and does not know the hidden column exists.

One disadvantage: you need to set AllowUserResizing to flexResizeNone to prevent the user from opening up the hidden column.

 
Private Sub Form_Load()
    ' Make some values.
    values = Array( _
        Array("Fruit", "Color", "Animal", "Sport", "Drink", _
            "Game", "Computer"), _
        Array("Banana", "Blue", "Cheetah", "Robo Rally", _
            "Water", "Volleyball", "Pavilion"))

    ' Prepare the FlexGrids.
    With MSFlexGrid1(0)
        .SelectionMode = flexSelectionByRow
        .Cols = 2
        .Rows = 2 + UBound(values(0))
        .FixedCols = 0
        .ColWidth(0) = .Width / 2 - 60
        .ColWidth(1) = .Width / 2 - 60
    End With

    With MSFlexGrid1(1)
        .SelectionMode = flexSelectionByRow
        .Cols = 3
        .Rows = 2 + UBound(values(0))
        .FixedCols = 0
        .ColWidth(0) = 0
        .ColWidth(1) = .Width / 2 - 60
        .ColWidth(2) = .Width / 2 - 60

        .AllowUserResizing = flexResizeNone
    End With

    ' Display the values.
    MSFlexGrid1(0).TextMatrix(0, 0) = "Item"
    MSFlexGrid1(0).TextMatrix(0, 1) = "Value"
    MSFlexGrid1(1).TextMatrix(0, 1) = "Item"
    MSFlexGrid1(1).TextMatrix(0, 2) = "Value"

    For r = 1 To MSFlexGrid1(0).Rows - 1
        MSFlexGrid1(0).TextMatrix(r, 0) = values(0)(r - 1)
        MSFlexGrid1(0).TextMatrix(r, 1) = values(1)(r - 1)
        MSFlexGrid1(1).TextMatrix(r, 1) = values(0)(r - 1)
        MSFlexGrid1(1).TextMatrix(r, 2) = values(1)(r - 1)
    Next r
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated