pigface
asked on
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.
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.
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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Object = "{5E9E78A0-531B-11CF-91F6-
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(Mu
MultiSelectArray(UBound(Mu
Debug.Print MultiSelectArray(UBound(Mu
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(KeyCod
' 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