ctrl key and MS Flex Grid

I have screen that uses flex grid and need to do the following three things

select a single row and assign and action from a combo box (this is working)

select multiple rows using shift and assign and action from a combo box to these rows (this is working using row and rowsel)

select multiple rows using CTRL and assign and action from a combo box to these rows - this one is not working and I am unsure of how to tackle this.  Does anyone have any code that can determine what rows have been highlighted via the ctrl key and perform an action against these rows?

Thanks.
pigfaceAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

g0rathCommented:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   5520
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6675
   LinkTopic       =   "Form1"
   ScaleHeight     =   5520
   ScaleWidth      =   6675
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command2
      Caption         =   "Reset"
      Height          =   495
      Left            =   3720
      TabIndex        =   3
      Top             =   3840
      Width           =   1575
   End
   Begin VB.ComboBox Combo1
      Height          =   315
      Left            =   720
      TabIndex        =   2
      Text            =   "Testing"
      Top             =   4440
      Width           =   3975
   End
   Begin VB.CommandButton Command1
      Caption         =   "Populate Data"
      Height          =   975
      Left            =   1920
      TabIndex        =   1
      Top             =   480
      Width           =   2415
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
      Height          =   1695
      Left            =   960
      TabIndex        =   0
      Top             =   1800
      Width           =   4575
      _ExtentX        =   8070
      _ExtentY        =   2990
      _Version        =   393216
      Cols            =   3
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public MultipleSelect As Boolean
Private MultiSelectArray() As Integer
Public MultiIndex As Integer

Private Sub PrintValues()
    Dim i As Integer
    Dim msg As String
    msg = ""
    For i = 0 To UBound(MultiSelectArray) - 1
        msg = msg & " " & MultiSelectArray(i)
    Next i
    MsgBox msg
    ' At this point we have all the selections that you chose
    ' do whatever
End Sub
Private Sub Combo1_Click()
    PrintValues
End Sub

Private Sub Command1_Click()
    MSFlexGrid1.AddItem "1" & vbTab & "A" & vbTab & "100"
    MSFlexGrid1.AddItem "2" & vbTab & "B" & vbTab & "100"
    MSFlexGrid1.AddItem "3" & vbTab & "C" & vbTab & "100"
    MSFlexGrid1.AddItem "4" & vbTab & "D" & vbTab & "100"
    MSFlexGrid1.AddItem "5" & vbTab & "E" & vbTab & "100"
    MSFlexGrid1.AddItem "6" & vbTab & "F" & vbTab & "100"
    MSFlexGrid1.AddItem "7" & vbTab & "G" & vbTab & "100"
    MSFlexGrid1.AddItem "8" & vbTab & "H" & vbTab & "100"
    MSFlexGrid1.AddItem "9" & vbTab & "I" & vbTab & "100"
   
    MSFlexGrid1.Row = 5
    MSFlexGrid1.CellFontBold = True
   
    Combo1.AddItem "1"
    Combo1.AddItem "2"
    Combo1.AddItem "3"
End Sub
Private Sub DeselectAllRows()

    Dim lRowOriginal As Long
    With MSFlexGrid1
        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 SelectMultiple()

    Dim lRowOriginal As Long

    Debug.Print "----------"
    Debug.Print MSFlexGrid1.MouseRow
    Debug.Print MSFlexGrid1.Row
    With MSFlexGrid1
        .Col = .FixedCols
        .RowSel = .Row
        .ColSel = .Cols - 1
        .CellBackColor = vbHighlight
        .CellForeColor = vbHighlightText
        ReDim Preserve MultiSelectArray(UBound(MultiSelectArray) + 1)
        MultiSelectArray(UBound(MultiSelectArray) - 1) = .Row
        Debug.Print MultiSelectArray(UBound(MultiSelectArray) - 1)
    End With
End Sub

Private Sub Command2_Click()
    ReDim MultiSelectArray(0)
    DeselectAllRows
End Sub

Private Sub Form_Load()
    ReDim MultiSelectArray(0)
End Sub

Private Sub MSFlexGrid1_Click()
    If MultipleSelect Then
        SelectMultiple
    End If
End Sub

Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    ' And Not to stop multiple iterations of this event firing
    If KeyCode = 17 And Not MultipleSelect Then
        Debug.Print "KeyDown firing again"
        MultipleSelect = True
        DeselectAllRows
    End If
End Sub

Private Sub MSFlexGrid1_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 17 Then
        MultipleSelect = False
    End If
End Sub
0
g0rathCommented:
Here's an example of it working....multiple graphical selections, and also saving it to an array...then just reading the rows from the array when you hit your combo box event.
0
pigfaceAuthor Commented:
This works, but on the assumption that the user click ctrl everytime that they want a row rather than keeping ctrl pressed and seecting several rows.  By keep ctrl down and selecting several rows, only the last row is recorded when the ctrl is released.

0
g0rathCommented:
This example will only highligh rows if you hold down the CTRL key. When you release the CTRL key the highligh event no longer occurs.

If you hit the CTRL key again it resets the graphical highlighting, but your right there is a bug in that function

Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    ' And Not to stop multiple iterations of this event firing
    If KeyCode = 17 And Not MultipleSelect Then
        Debug.Print "KeyDown firing again"
        MultipleSelect = True
        DeselectAllRows
+      ReDim MultiSelectArray(0)
    End If
End Sub

Add the line with the + by it

Follow the events.

The Click event can only occur if the MultipleSelect is true, and that only becomes true when you fire the KeyDown Event, and it gets released on KeyUp

If you try to step through this via the IDE using 'F8' it doesn't occur properly as the IDE causes some events of its own.

When you can do the MouseClick the row that you have selected gets highlighted, now you will need to write logic to not add the same row if you click the same row multiple times...but I was hoping to give you enough of a skeleton to go and modify it to your needs.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.