Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-31
3
Medium Priority
?
1,107 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
Comment
Question by:Etzie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 1500 total points
ID: 12457469
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
ID: 12457911
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
ID: 12470848
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

610 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