Change color of individual rows in a datagrid 
Author Message
 Change color of individual rows in a datagrid

Hi,

my problem was often named here in the past, but I did not find any
answers which would help me.

I want to change the color of some complete rows in a winform datagrid
by code like this:

Datagrid1.row(3).backcolor = color.red
Datagrid1.row(7).backcolor = color.blue

To implement this in the paint event of the DataGridTextBoxColumn like
shown at http://www.*-*-*.com/ #q745q wont
be a solution which will help me, because the color is not depending of
a value in the specific cell, but is given from external criteria.

Thanks for any help,
                regards,
                        Martin.

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sat, 05 Mar 2005 23:25:32 GMT  
 Change color of individual rows in a datagrid
Martin,

I think you can do this with the techniques of that FAQ. Notwithstanding the
title of the FAQ, the color of a cell does not have to depend on the value
of another cell. It actually could be determined by the row you are in (or
some other criteria). So, instead of deciding the color based on a cell
value, decide it based on the row passed in.

The third technique discussed in that FAQ even gives you greater
flexibility. It uses an event that you can subscribe to furnish the color
for cell on demand. So, when the grid is ready to paint cell 2,3, this event
is fired asking you to provide the color you want to see in cell 2,3 at that
particular time. You can use whatever external criteria you want to use to
determine the color you furnish.

There are no properties to set row color like you want to use. Until
Microsoft adds them (or you subclass DataGrid, and add your own properties,
say, using techniques from the FAQ), I think you'll have to use other
techniques to get at setting the colors.

=======================
Clay Burch

Syncfusion, Inc.
Visit www.syncfusion.com to download a free trial of Essential Suite


Quote:
> Hi,

> my problem was often named here in the past, but I did not find any
> answers which would help me.

> I want to change the color of some complete rows in a winform datagrid
> by code like this:

> Datagrid1.row(3).backcolor = color.red
> Datagrid1.row(7).backcolor = color.blue

> To implement this in the paint event of the DataGridTextBoxColumn like
> shown at http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q745q won't
> be a solution which will help me, because the color is not depending of
> a value in the specific cell, but is given from external criteria.

> Thanks for any help,
> regards,
> Martin.

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Sun, 06 Mar 2005 19:20:47 GMT  
 Change color of individual rows in a datagrid
Clay,

thanks for your fast answer.

I took the 3rd technique (providing the event) and modified it so that I
can set the brush in the eventargs (e.Brush) and not an enabledvalue. So
I can individually set the color by the routine, which handles this
event.

And it works!

Thanks again,
regards,
    Martin.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Mon, 07 Mar 2005 23:11:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DataGrid: Can you color code individual rows?

2. Changing individual row colors in a ListView

3. ListView Control ... changing background color of individual rows

4. MSFlexGrid - Change individual Cell or Row Colors?

5. How to change color of individual cell DataGrid.

6. question on changing row color by specified cell value in winform datagrid

7. Changing the color of a specified row in a datagrid

8. Change specific row colors in a bound datagrid

9. Change color of DataGrid Row

10. Change the color of a row in a datagrid-

11. Change Row Color for DataGrid?

12. change background color for selected row in datagrid?

 

 
Powered by phpBB® Forum Software