471,305 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

coloring rows in a datagridView

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 ?

--
rgds, Wilfried
http://www.mestdagh.biz
Dec 5 '05 #1
5 1921
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.com> wrote in
message news:FC**********************************@microsof t.com...
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 ?

--
rgds, Wilfried
http://www.mestdagh.biz

Dec 5 '05 #2
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 ?

--
rgds, Wilfried
http://www.mestdagh.biz
Dec 5 '05 #3
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.com> wrote in
message news:96**********************************@microsof t.com...
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 ?

--
rgds, Wilfried
http://www.mestdagh.biz

Dec 5 '05 #4
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 ?

--
rgds, Wilfried
http://www.mestdagh.biz
Dec 5 '05 #5

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.com> wrote in
message news:A4**********************************@microsof t.com...
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 ?

--
rgds, Wilfried
http://www.mestdagh.biz


MSDN contains a bunch of samples, guess this might be what you are looking
for:

http://msdn2.microsoft.com/en-us/lib...cellstyle.aspx

Willy.
Dec 5 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Luca Beretta | last post: by
4 posts views Thread by craig.wenger | last post: by
reply views Thread by Firona | last post: by
6 posts views Thread by =?Utf-8?B?TU1TSkVE?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.