Solved

Multiple Selection in MSFlexgrid

Posted on 2003-11-20
13
5,947 Views
Last Modified: 2009-12-25
Which property of MSFlexgrid allows the user to select multiple rows for processing?
0
Comment
Question by:scmmicro
[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
13 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 9786497
Hi scmmicro,

You can only select consecutive rows by setting the .Row and .RowSel properties. You cannot by default select non-consecutive rows unless you manage all of this yourself.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9786543
Hi!

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
--------------------------------------------------------------


0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9786597
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:scmmicro
ID: 9786751
Can u send me the sample code for the same (using .row and .rowsel properties) ?
0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 20 total points
ID: 9787116
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 9

Expert Comment

by:dancebert
ID: 9788433
Here is my library code for managing row selection.  It requires use of a fixed column in the grid.

Private m_IsOnFixedPart As Boolean
Private m_IsZeroRow As Boolean

Private Sub oGrid_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)

    ' Are we on fixed column?  If so, highlight row(s)
   
    With oGrid
        If .Rows = 0 And .Cols = 0 Then
            Exit Sub
        End If
       
        ' After deselecting rows, need these to get back to original cell
        Dim lRowOriginal As Long: lRowOriginal = .MouseRow
        Dim lColOriginal As Long: lColOriginal = .MouseCol
   
        ' Don't understand this, the code was downloaded.
        Dim l As Long
        Dim lWidth As Long
        For l = 0 To .Cols - 1
            If .ColIsVisible(l) Then
                lWidth = lWidth + .ColWidth(l)
            End If
        Next
       
        If .RowHeightMin = 0 Then
            m_IsOnFixedPart = (x < .ColWidth(0)) Or _
                       (x > lWidth) Or _
                       (y < .RowHeight(0))
        Else
            m_IsOnFixedPart = (x < .ColWidth(0)) Or _
                       (x > lWidth) Or _
                       (y < .RowHeight(0)) Or _
                       (y > .Rows * .RowHeightMin)
        End If
                       
        m_IsZeroRow = (.RowHeight(0) >= y)
       
       
        '' Highlighting
        If Not m_IsOnFixedPart Or m_IsZeroRow Then
            DeselectAllRows
            .Row = lRowOriginal
            .Col = lColOriginal
        Else
            If (Shift And vbShiftMask) = vbShiftMask Then
                SelectContigious 'Select from the current row to the clicked row
            ElseIf (Shift And vbCtrlMask) = vbCtrlMask Then
                ToggleSelect  'Toggle the select in the clicked row
            Else
                 DeselectAllRows
               
                'select clicked row
                 .RowSel = .Row
                 .ColSel = .Cols - 1
                .CellBackColor = vbHighlight
                .CellForeColor = vbHighlightText

            End If  '' If (Shift And vbShiftMask) = vbShiftMask Then
        End If  '' If Not m_IsOnFixedPart Or m_IsZeroRow Then
    End With
End Sub


Private Sub DeselectAllRows()
   
    Dim lRowOriginal As Long
    With oGrid
        lRowOriginal = .Row
        .Row = .FixedRows
        .Col = .FixedCols
        .RowSel = .Rows - 1
        .ColSel = .Cols - 1
        .FillStyle = flexFillRepeat
       
        .HighLight = flexHighlightNever
        .CellBackColor = .BackColor
        .CellForeColor = .ForeColor
        .Row = lRowOriginal
        .ColSel = .Cols - 1
    End With

End Sub

Private Sub SelectContigious()
'Select from the current row to the clicked row
    Dim lRow As Long
    Dim lMouseRow As Long

    With oGrid
        lRow = .Row
        lMouseRow = .MouseRow
        .FillStyle = flexFillRepeat
        .Row = lRow
        .Col = .FixedCols
        .RowSel = lMouseRow
        .ColSel = .Cols - 1
        .HighLight = flexHighlightNever
        .CellBackColor = vbHighlight
        .CellForeColor = vbHighlightText
    End With
End Sub

Private Sub ToggleSelect()
 'Toggle the select in the clicked row
    With oGrid
        .Row = .MouseRow
        .FillStyle = flexFillRepeat
        .Col = .FixedCols
       
        .ColSel = .Cols - 1
        .HighLight = flexHighlightNever
        If .CellBackColor = vbHighlight Then
            .CellBackColor = .BackColor
            .CellForeColor = .ForeColor
        Else
            .CellBackColor = vbHighlight
            .CellForeColor = vbHighlightText
        End If
    End With
End Sub
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 10595535
Thanks
0
 

Expert Comment

by:Tamilselvan
ID: 26034811
answer I expected is not  this.  when i click  first row . first row selects.  when i click second row, both of first row and second row are selected. my requirement is when i click second row, second row should be  selected only. first row should not be selected
0
 

Expert Comment

by:Tamilselvan
ID: 26121489
please , I want proper answer for this question
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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

738 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