Build a multi-coloured Data bound Grid.

I

iKiLL

Hi all

I am currently using a Bound Read Only data grid.

What I am looking to do is have different colour rows depending on the data
in the row.

EG. If the status = Closed then that row should be Red, If the Status = Open
then That row should be Green.

I am trying not to loop through all the rows setting the Back colour of each
row or I may as well not bother binding the grid.

Any ideas?

Thanks.
ink
 
C

ClayB

If this is a DataGridView, then you could try handling the RowPrePaint
event and there conditionally set the BackColor.

void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex == 1)
dataGridView1.Rows[1].DefaultCellStyle.BackColor =
Color.Red;
else if(e.RowIndex == 3)
dataGridView1.Rows[3].DefaultCellStyle.BackColor =
Color.Blue;
}
==================
Clay Burch
Syncfusion, Inc.
 
G

Guest

THis document has a lot of anwers to questions liek yours:

http://www.windowsforms.net/Samples/Go To Market/DataGridView/DataGridView FAQ.doc

It is GREAT!


iKiLL said:
Thanks for the advice Clay.

i will give this a try.




ClayB said:
If this is a DataGridView, then you could try handling the RowPrePaint
event and there conditionally set the BackColor.

void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex == 1)
dataGridView1.Rows[1].DefaultCellStyle.BackColor =
Color.Red;
else if(e.RowIndex == 3)
dataGridView1.Rows[3].DefaultCellStyle.BackColor =
Color.Blue;
}
==================
Clay Burch
Syncfusion, Inc.
 
I

iKiLL

Thanks Chris

i will take a look



Chris said:
THis document has a lot of anwers to questions liek yours:

http://www.windowsforms.net/Samples/Go To Market/DataGridView/DataGridView FAQ.doc

It is GREAT!


iKiLL said:
Thanks for the advice Clay.

i will give this a try.




ClayB said:
If this is a DataGridView, then you could try handling the RowPrePaint
event and there conditionally set the BackColor.

void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex == 1)
dataGridView1.Rows[1].DefaultCellStyle.BackColor =
Color.Red;
else if(e.RowIndex == 3)
dataGridView1.Rows[3].DefaultCellStyle.BackColor =
Color.Blue;
}
==================
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top