Click to See Complete Forum and Search --> : MSFlexGrid
Dr_Michael
August 5th, 1999, 03:18 AM
I use an MSFlexGrid with 7 rows and 10 columns. I want to display on its cells only colors and specifically only two diferent colors. When it begins I want it to be white and when the user selects an area to become blue and remain blue. When the user selects another area I want it also to remain blue and so on. Finally I want to let the user deselect an area (by dragging again) and to paint it white again. Any ideas?
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Chris Eastwood
August 5th, 1999, 03:52 AM
Hi
Create a form with your flexgrid on (MSFlexGrid1) and paste in the following code :
private Sub Form_Load()
With MSFlexGrid1
.Rows = 7
.Cols = 10
.SelectionMode = flexSelectionFree
.FixedRows = 0
.FixedCols = 0
End With
End Sub
private Sub MSFlexGrid1_MouseUp(Button as Integer, Shift as Integer, x as Single, y as Single)
Dim lStartRow as Long
Dim lEndRow as Long
Dim lStartCol as Long
Dim lEndCol as Long
Dim lRCount as Long
Dim lCCount as Long
With MSFlexGrid1
lStartRow = IIf(.RowSel < .Row, .RowSel, .Row)
lEndRow = IIf(.RowSel < .Row, .Row, .RowSel)
lStartCol = IIf(.ColSel < .Col, .RowSel, .Col)
lEndCol = IIf(.ColSel < .Col, .Col, .ColSel)
.Redraw = false
for lRCount = lStartRow to lEndRow
for lCCount = lStartCol to lEndCol
.Row = lRCount
.Col = lCCount
If .CellBackColor = vbBlue then
.CellBackColor = vbWhite
else
.CellBackColor = vbBlue
End If
next
next
.Redraw = true
.Col = .MouseCol
.Row = .MouseRow
.ColSel = .Col
.RowSel = .Row
End With
End Sub
Works fine here !
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Dr_Michael
August 5th, 1999, 04:14 AM
1) Instead of vbBlue color try this: &H8000000D
2) Also set the grid property highlight to: "always"
P.S. I think this code has one bug: Try the selection not starting by left-up corner but by right-down. What is going on there?
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Chris Eastwood
August 5th, 1999, 04:26 AM
I just knocked this code out for you to try - I'm certainly not going to bug-fix it as well ;-)
I wouldn't actually use the '&H8000000D' value - try using the vb constant 'vbHighlight' - the user just might change their display settings. I used vbBlue because I'm just lazy :)
>P.S. I think this code has one bug: Try the selection not starting by
>left-up corner but by right-down. What is going on there?
? What do you mean ?
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Dr_Michael
August 5th, 1999, 04:34 AM
You are right about the color! Thanx!
About the bug now:
I mean that it works well if you start dragging form the UPPER-LEFT corner. If you try to select a region from the DOWN-RIGHT corner of the region then something wrong happens... Can you try it plz?
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Chris Eastwood
August 5th, 1999, 04:52 AM
Found it :
My fault entirely, you need to change the 'lStartCol' line to read :
lStartCol = IIf(.ColSel < .Col, .ColSel, .Col)
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Dr_Michael
August 5th, 1999, 05:02 AM
Thanx Chris! I couldn't not to rate it :-)
Well one more expansion:
Take a look at the following scenario:
The user has selected some regions but when it selects a new region that contains some cells of another already selected, then it deselects the common cells. That is not desirable.
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.