scbdpm
asked on
msFlexGrid- change seleced cell background
I found code here on EE to change the background color of the selected cell(s) of an MSFlexGrid.
However, the code works no matter how many cells are chosen.
I would like to have just one cell per row highlighted/color change.
In other words, my end users will be allowed to select one item per row on the MSFlexGrid and I would like to highlight this item. If they choose another item on that same row, I would like the first cell to change color back to white and then the newly selected cell to change to red, let's say (kind of like radio buttons...)
However, the code works no matter how many cells are chosen.
I would like to have just one cell per row highlighted/color change.
In other words, my end users will be allowed to select one item per row on the MSFlexGrid and I would like to highlight this item. If they choose another item on that same row, I would like the first cell to change color back to white and then the newly selected cell to change to red, let's say (kind of like radio buttons...)
ASKER
appreciate the input but am looking for code that actually works....
am getting errors trying to figure out what you've suggested.
am getting errors trying to figure out what you've suggested.
Please try this.
Private Sub Form_Activate()
For i = 1 To MSFlexGrid1.Rows - 1
For j = 0 To MSFlexGrid1.Cols - 1
With MSFlexGrid1
.Row = i
If (i Mod 2) = 0 Then
.Col = j: .CellBackColor = vbRed '&HFFFF80
Else
.Col = j: .CellBackColor = vbBlue '&HFFFF80
End If
End With
Next
Next
End Sub
Private Sub Form_Load()
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.Cols = 4
MSFlexGrid1.Rows = 10
MSFlexGrid1.TextMatrix(0, 0) = "Data1"
MSFlexGrid1.TextMatrix(0, 1) = "Data2"
MSFlexGrid1.TextMatrix(0, 2) = "Data3"
MSFlexGrid1.TextMatrix(0, 3) = "Data4"
End Sub
Regards,
M.Raja
Private Sub Form_Activate()
For i = 1 To MSFlexGrid1.Rows - 1
For j = 0 To MSFlexGrid1.Cols - 1
With MSFlexGrid1
.Row = i
If (i Mod 2) = 0 Then
.Col = j: .CellBackColor = vbRed '&HFFFF80
Else
.Col = j: .CellBackColor = vbBlue '&HFFFF80
End If
End With
Next
Next
End Sub
Private Sub Form_Load()
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.Cols = 4
MSFlexGrid1.Rows = 10
MSFlexGrid1.TextMatrix(0, 0) = "Data1"
MSFlexGrid1.TextMatrix(0, 1) = "Data2"
MSFlexGrid1.TextMatrix(0, 2) = "Data3"
MSFlexGrid1.TextMatrix(0, 3) = "Data4"
End Sub
Regards,
M.Raja
ASKER
raja_ind82:
this code doesn't work either.
if I try to run wihout breaks, it locks up the app.
if I step trhough, there isn't any change to cell colors.....
to all future posters:
please re-read my initial post. I am looking for solutions that work!
this code doesn't work either.
if I try to run wihout breaks, it locks up the app.
if I step trhough, there isn't any change to cell colors.....
to all future posters:
please re-read my initial post. I am looking for solutions that work!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
raja_ind82:
thank you! that did what I wanted.
thank you! that did what I wanted.
ASKER
raja_ind82:
I have another question open on MSFlexGrid:
https://www.experts-exchange.com/questions/22858438/msFlexGrid-get-selected-cells-in-each-row.html
can you see if you can help me there too.
I am closing this point
I have another question open on MSFlexGrid:
https://www.experts-exchange.com/questions/22858438/msFlexGrid-get-selected-cells-in-each-row.html
can you see if you can help me there too.
I am closing this point
for i=0 to msflexgrid1.cols-1
msflexgrid1.cell(selectedr
next
msflexgrid1.cell(msflexgri
//msflexgrid.row means the current row
//msflexgrid.col means the current column
OR else
In the "Entercell" event of the Msflexgrid, get column no and row no (as Public variables) and set the color. In the Leave cell event make the previous column as white and current column as red
Note: Currently i don't have Vb installed in my machine and so just given the outline of the code