Solved

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

Posted on 2004-10-31
756 Views
Last Modified: 2010-05-18
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
Question by:Etzie
    3 Comments
     
    LVL 18

    Accepted Solution

    by:
    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
     
    LVL 48

    Expert Comment

    by:Mikal613
    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
     
    LVL 1

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now