how do i change the background color of different rows in a MXFlexGrid ?
Printable View
how do i change the background color of different rows in a MXFlexGrid ?
Hi hyousuf2 and welcome to VBFORUMS. :wave:
Give it a try to this sample and let me know:
VB Code:
With MXFlexGrid1 For i = 1 To .Rows If i Mod 2 = 0 Then For j = 0 To .Cols - 1 .Row = i .Col = j .CellBackColor = vbYellow Next j Else For j = 0 To .Cols - 1 .Row = i .Col = j .CellBackColor = vbGreen Next j End If Next i End With
hi rhinobull, that code worked well, jus tell me one more thing. how do i assign custom colors other than vbGreen or vbYellow e.t.c
Open your form in design and go to properties. Select Backcolor and choose any color you want. Then just copy that value from properties window and paste it to replace any of those colors I used in my sample. Do the same thing for the second color but don't forget to reset your form's backcolor to whatever it was.
Here is a sample of custome colors:
VB Code:
With HFGrid For i = 1 To .Rows - 1 If i Mod 2 = 0 Then For j = 0 To .Cols - 1 .Row = i .Col = j .CellBackColor = &HE1F9FF 'lite yellow Next j Else For j = 0 To .Cols - 1 .Row = i .Col = j .CellBackColor = &HC5CEFE 'light red Next j End If Next i End With
I would recommend that you create CONSTANTS in some module for these custom colors. Searching around for values in code later on, when you want to change colors - is a pain.
We actually use GLOBAL VARIABLES - so that the colors could potentially be different from user to user - haven't actually implemented that yet, but using GLOBAL VARIABLES will allow us to.
Also, be careful about what colors you choose. Some monitors, video cards, and especially projectors, do not represent colors exactly the same. In our shop we stick to simple colors - either the 8 that VB offer, or ramp up to the extra 8 you get with QBCOLOR. Just to keep it simple...
Top of some module...
In our MDI Parent Form Load event...Code:Public gColorDirtyGrid As Long
Public gColorCleanGrid As Long
Public gColorHotBox As Long
Public gColorHighLight As Long
Public gColorDirty As Long
Public gColorClean As Long
Public gColorLetter As Long
Public gColorMatch As Long
Public gColorMatchLetter As Long
Code:gColorHotBox = QBColor(11) ' vbCyan
gColorDirtyGrid = QBColor(7) ' White
gColorHighLight = QBColor(14) ' vbYellow / Light Yellow
gColorDirty = QBColor(10) ' vbGreen / Light Green
gColorClean = QBColor(15) ' vbWhite / Bright White
gColorMatch = QBColor(5) ' Magenta
gColorMatchLetter = QBColor(14) ' vbYellow / Light Yellow
gColorLetter = vbBlack
I agree: declaring at the module level some color consts will be a big help down the road, however you still have to find those that you believe are the ones and also neither VB nor QBColor offer any decent color range so working with true colors palette is what I recommend.
In the old days when computer video cards weren't really that great using true colors could be very problematic but these nova days it's totally safe.
We sell software to school districts - they have no money to upgrade old computers - you would be surprised at what we encounter for old PC's and monitors - running 800x600 (and even less sometimes)...Quote:
Originally Posted by RhinoBull
We also have some nice commercial customers - flat screen LCD monitors...
Quite a stretch to support...
Yea, you could be right. As a matter of fact the friend of mine supports small business that has few 486s and a couple of P1-160 ... :p
well thnkx mr rhino bull but actually i posted that reply abt a day back n u dintt reply dats y i had to post an extra thread. but neva da less i have really got ur details workin now !
"Extra tread" doesn't usualy help much - it's nothing more but a way to overload board with identical questions rather than just wait for proper respond in the original.
But I'm glad that you've managed to have it working. :thumb: