1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
option explicit
Enum ModifierKeysEnum
mkNone = 0
mkShift = 1
mkControl = 2
End Enum
Private ModifierKey As ModifierKeysEnum
Private Sub grdLevel1_Click()
Dim CurrentClickedRow As Long
Dim i As Long
With grdLevel1
CurrentClickedRow = .MouseRow
If CurrentClickedRow = 0 Then Exit Sub
If CurrentClickedRow = .Rows - 1 Then Exit Sub
.Visible = False
Select Case ModifierKey
Case mkNone 'Clear all highlights and highlight this row
Screen.MousePointer = vbHourglass
.Col = 1
For i = 1 To .Rows - 2
.Row = i
If .CellBackColor = vbDarkBlue Then
HighlightRow grdLevel1, hsOff
End If
Next i
.Row = CurrentClickedRow: HighlightRow grdLevel1, hsOn
Screen.MousePointer = vbDefault
Case mkShift 'Highlight all rows between this row and mLastRow
.Row = CurrentClickedRow
If mLastRow = CurrentClickedRow Or mLastRow = -1 Then
HighlightRow grdLevel1, hsOn
ElseIf mLastRow > CurrentClickedRow Then
For i = CurrentClickedRow To mLastRow
.Row = i: HighlightRow grdLevel1, hsOn
Next i
Else
For i = mLastRow To CurrentClickedRow
.Row = i: HighlightRow grdLevel1, hsOn
Next i
End If
Case mkControl 'Toggle highlight state of clicked row
HighlightRow grdLevel1, IIf(.CellBackColor = vbDarkBlue, hsOff, hsOn)
End Select
mLastRow = CurrentClickedRow
.Visible = True
End With 'grdLevel1
Screen.MousePointer = vbDefault
End Sub
'-----------------
Public Sub HighlightRow(aGrid As MSFlexGrid, NewState As HighlightState)
Dim i As Integer
With aGrid
For i = 0 To .Cols - 1
.Col = i
.CellBackColor = IIf(NewState = hsOff, vbWhite, vbDarkBlue)
.CellForeColor = IIf(NewState = hsOff, vbBlack, vbWhite)
Next i
End With 'aGrid
End Sub |
Partager