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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid control variable colour

Status
Not open for further replies.

AOLBoy

IS-IT--Management
May 7, 2002
68
GB
Hi,
In my VB6 project I am using a datagrid control to show information retreived using an ADO control. Is there anyway that I can vary the colour on a row based on the information contained in that row? Any help would be gratefully accepted.
 
It's a lot easier using MSHFlexgrid. You need to add the component to your project. It's file is MSHFlxGd.ocx

It has individual control of text, forecolor and backcolor at the individual cell level, and it's all covered in VBHelp Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Hi,
You can set the back color of the datagrid using the BackColor property as follows:

DataGrid1.BackColor = vbBlue

You can even use the DB Grid control as it provides Cell level color setting. I believe the format there is:

DBGrid1.Cells(column,row).BackColor = vbBlue

However, I am not sure if it is coorect. You could just check it out.

Hope it helps. Let me know what happens.
With regards,
PGK
 

pgk:
The question was:
>"Is there anyway that I can vary the colour on a row based on the information contained in that row?"

DataGrid1.BackColor changes the color for the whole grid.

>"You can even use the DB Grid control as it provides Cell level color setting. I believe the format there is:"

No it doesn't.

>DBGrid1.Cells(column,row).BackColor = vbBlue

No such method or property or not even close to it.



AOLBoy: To do this you will need to use the flex grid as johnwm has already mentioned. A DBGrid or DataGrid does not have this possibility.
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Hi cclint,
Thanks for pointing out that DB Grid does not have these properties. I put in DBGrid instead of MSFlexGrid.

The syntax for changing the color of the first column of the first row in a FlexGrid is

MSFlexgrid1.Row=0
MSFlexgrid1.Col=0
MSFlexgrid1.CellBackColor=vbYellow

Hope I haven't got this wrong ;-) Hope it helps. Let me know what happens.
With regards,
PGK
 
I also sometimes read things too fast[smile] [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
As I said yesterdat....Flexgrid!

AOLboy,

Did this solve your problem? Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 

johnwm, I already pointed the error out to pgk and pgk already responded to the mistake. It wasn't a question anymore of what grid is needed, in order to do the color thing.


Ili: Just color the visible rows. And do this when the grid scrolls or resizes. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks for all your assistance, I have managed to solve my problem using MSHFlexGrid. I am now in the process of changing my existing Datagrids to MSHFlexigrids.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top