Solved

Multiple Selection in MSFlexgrid

Posted on 2003-11-20
13
5,908 Views
Last Modified: 2009-12-25
Which property of MSFlexgrid allows the user to select multiple rows for processing?
0
Comment
Question by:scmmicro
13 Comments
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:scmmicro
Comment Utility
Can u send me the sample code for the same (using .row and .rowsel properties) ?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Accepted Solution

by:
dbrckovi earned 20 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0
 

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now