select multiple cells in MSHFlexGrid
I have a program and need to select multible cells in a HSHFlexGrid.
I have it working the the folloing code with some issues
Here is what I want I want to select mulitble cells but only one cell per col I must be able to know what cells are picked later.
The problems are is there a better way to set the cellbackcolor? Stepping thou all cells take long on some larger grids. I have the backcollor changed depending on what is in there so I can not globaly set all backcolor.
Is there a better way to do what I am trying?
Is there a faster way to clear the cell backcolor?
VB Code:
Dim multi As Boolean
Dim TargetSelect(200) As Integer ' max cols possible
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
' do not want row or col 0
If MSHFlexGrid1.MouseCol > 0 And MSHFlexGrid1.MouseRow > 0 Then
If Button = vbLeftButton Then
Dim lngColor As Long
If Shift = vbCtrlMask Then
' Only one want cell allowed per col
If TargetSelect(MSHFlexGrid1.Col) < 1 Then
lngColor = MSHFlexGrid1.BackColor
If MSHFlexGrid1.CellBackColor = MSHFlexGrid1.BackColor Then
lngColor = MSHFlexGrid1.BackColorSel
TargetSelect(MSHFlexGrid1.Col) = 0
End If
With MSHFlexGrid1
.CellBackColor = lngColor
' save what cell is marked in this col
TargetSelect(.Col) = .Row
End With
mulit = True
End If
Else
If multi = True Then
lngColor = MSHFlexGrid1.BackColor
With MSHFlexGrid1
tmprow = .Row
tmpcol = .Col
' Take too long!
For a = 1 To .Cols - 1
.Col = a
TargetSelect(.Col) = 0
For b = 1 To .Rows - 1
.Row = b
If .CellBackColor = .BackColorSel Then
' Set all cell back to normal
.CellBackColor = lngColor
End If
Next b
Next a
.Row = tmprow
.Col = tmpcol
End With
End If
lngColor = MSHFlexGrid1.BackColor
If MSHFlexGrid1.CellBackColor = MSHFlexGrid1.BackColor Then
lngColor = MSHFlexGrid1.BackColorSel
TargetSelect(MSHFlexGrid1.Col) = 0
End If
With MSHFlexGrid1
.CellBackColor = lngColor
TargetSelect(.Col) = .Row
End With
multi = True
End If
End If
End If
End Sub
Re: select multiple cells in MSHFlexGrid
well i haven't tried to work out what you're trying to do, but here's how you change the backcolor of a groups of cells (without looping):
VB Code:
With MSFlexGrid1
.Redraw = False
.FillStyle = flexFillRepeat
' top left of the section you want to change
.Col = 1
.Row = 3
' bottom right of the section
.ColSel = 3
.RowSel = 5
' Set any cell properties
.CellBackColor = vbBlue
.FillStyle = flexFillSingle
.Redraw = True
End With
you might be interested in looking at the MSFlexGrid selection link in my signature for an example of this in practice.
Re: select multiple cells in MSHFlexGrid
Thanks but that will not work. I have the background color changed on some cells for other reasons and do not want to change them. I only want to change the ones back that have been selected.
Ron
1 Attachment(s)
Re: select multiple cells in MSHFlexGrid
ahh, ok.
i think i understand your problem - though maybe not entirely.
it's probably best to come at this from another angle. I've used a dictionary to record the position of the coloured cells - it'll be much much faster than looping through the entire grid.
Shift+Click on a cell to turn it Red, Ctrl-Click to turn it blue. It'll only allow one cell of each colour per column.
I'm not sure if it does what you want cos i can't quite tell what you want - but I'm sure it can be modified.
feel free to ask if you have any questions