• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1227
  • Last Modified:

selecting multiple rows in MS Flex Grid using CTRL and/or SHIFT

I have an MS Flexgrid control on a form.
I wish to select multiple single rows by holding the CTRL key and clicking on the row, and/or a range of rows by holding the SHIFT key and pressing the first and last rows (the Range using SHIFT works but I can't add a single row or another range to the selection).
The Flexgrid's SelectionMode is 'By Row'
0
Etzie
Asked:
Etzie
1 Solution
 
JR2003Commented:
I'm fairly certain you cannot multi-select non-contiguous rows on a FlexGrid. You can however do this on a ListView control, so if it is important it might be worth switching to the ListView control with its 'View' mode set to lvwReport.

JR
0
 
Mikal613Commented:
First set AllowBigSelection = True which will allow a selection by single click on a row or a column.
Set SelectionMode to 1,2 or 3 to allow selection of only rows, only columns, or both.

After that you can use properties row, col, rowsel and colsel to determine what is selected

Try this example:
Place Msflexgrid and 4 textboxes to a form and paste this code.
Run it and try selecting something.
----------------------------------------------------------------------------------
Private Sub Form_Load()
    MSFlexGrid1.Cols = 10
    MSFlexGrid1.Rows = 10
End Sub

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Text1.Text = "Row: " & MSFlexGrid1.Row
    Text2.Text = "RowSel: " & MSFlexGrid1.RowSel
    Text3.Text = "Col: " & MSFlexGrid1.Col
    Text4.Text = "ColSel: " & MSFlexGrid1.ColSel
End Sub


If you wish to select non-consecutive, then you could use an array which will hold an information for each row (if it is selected or not).

Try example from:    http://webwarper.net/ww/~GZ/www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20803581.html      
to see a possible approach

Here is example which selects only rows.

Just add msflexgrid to form, execute and try selecting something.

----------------------------------------------------------------
Private Sub Form_Load()
    MSFlexGrid1.Cols = 10               'Set dimensions of flexgrid and set selection behaviour
    MSFlexGrid1.Rows = 10
   
    MSFlexGrid1.AllowBigSelection = True
    MSFlexGrid1.SelectionMode = flexSelectionByRow
       
    For x = 0 To 9                      'Used for filling a flexgrid with some data
        For y = 0 To 9
            MSFlexGrid1.Col = x
            MSFlexGrid1.Row = y
            MSFlexGrid1.Text = y
        Next y
    Next x

End Sub

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim StartRow As Integer
    Dim EndRow As Integer
   
    'Depending on the selection direction, Row can be either smaller or larger than RowSel
    'So we must determine which is smaller and set StartRow and EndRow variables accordingly
   
    If MSFlexGrid1.Row < MSFlexGrid1.RowSel Then
        StartRow = MSFlexGrid1.Row
        EndRow = MSFlexGrid1.RowSel
    Else
        StartRow = MSFlexGrid1.RowSel
        EndRow = MSFlexGrid1.Row
    End If
   
    message = "Selected rows:" & Chr(13)                'chr(13) is used to enter new line
    For x = StartRow To EndRow                          'Add some text to message
        message = message & x & Chr(13)
    Next x
   
    MsgBox message

End Sub
0
 
atheekurrahmanCommented:
Set AllowBigSelection=TRUE
     SelectionMode=flexSelectionFree
     FocusRect=flexFocusNone.          //if u want the all the cells to be highlighted ven u select a row
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now