coloring rows in a datagridView

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I wants to set the background color of rows in a datagridView based on the
value of a particular cell. Someone knows how to do this ?
 
Wilfried,

In the data grid, you will have to create custom column styles (classes
derived from DataGridColumnStyle) which would paint the background based on
the row that you want to highlight. The DataGrid is very column-based, so
doing something like changing the row highlighting is difficult, to say the
least.

Basically, you have to create new versions of the DataGridColumnStyle
for your table, and then set the backgrounds appropriately.

Hope this helps.
 
Hi Nicholas,

Thanks for reply. It seems difficult and I'm not high experianced in dotNet.
Perhaps it is more simple to coloring just one cell depending on it's value ?
 
Wilfried,

As I stated before, the coloring is handled by the style for the column.
You can color individual cells, but you would have to create a custom column
style for each column and then paint the cell according to the contents.

Are you using .NET 2.0? If so, you can use the DataGridView, as this
allows for a per-cell rendering.
 
Hi Nicholas,

Ok I try to study it. Yes I'm using dotNet version 2 (still the beta
version) and using the dataGridView. Is it lot of work to give me a brief
example on how to etablish this ?
 

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

Back
Top