Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight Flexgrid row base on data 1

Status
Not open for further replies.

jayfox

Programmer
Dec 19, 2002
29
US
Hello, I have a mshflexgrid and this is the first time I used one. I would like to color rows based on criteria in my 3rd column which is name. For example, if its 'Smith' the entire row should be green or if it is Jones the entire row should be red and if the field is empty then the row will be yellow. And I would like this to be visible when they open the screen not when they select the row then the color will chnage so if you can tell me where the code should be place that will be helpful to. Thanks for any help.
 
You could try something like

With MSFlexGrid1
.Row = i
.Col = j
.CellBackColor = vbGreen
.Col = j + 1
.CellBackColor = vbCyan
 
Try this code,

MSFlexGrid1.Row = 4
MSFlexGrid1.Col = 0
MSFlexGrid1.RowSel = 4
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
MSFlexGrid1.FillStyle = flexFillRepeat
MSFlexGrid1.CellForeColor = vbWhite
MSFlexGrid1.CellBackColor = vbRed

You can make changes as needed.

Thanks and Good Luck!

zemp
 
How would I base it on certain criteria in the grid as a stated in the first example?
 
You will need to loop through the rows and check your criteria for each row. Something like this.

For i = 1 to msflexgrid1.rows-1 'start at 0 if you don't have headers
select case msflexgrid1.textmatrix(i,2)'2 for 3rd col
case "Smith"
...colour changing code for row i
case "Jones"
...etc.
end select
next i

Thanks and Good Luck!

zemp
 
Finally! Thanks Zemp! I'm an oldschool foxpro guy trying find my way around vb now. Thanks for the guidance.
 
Zemp, I also found your code to be very helpful therefore you deserve another star for that.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top