Hi,
At this time I'm able to set the background color of a cell depending
on it's value. I'm able to achieve this by extending the
DataGridTextBoxColumn class and overriding the Paint method:
[code]
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum,
System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool
alignToRight)
{
if (internalHighlightInformation != null)
{
object objAtRow = GetColumnValueAtRow(source, rowNum);
//(Values A, C and X are just an example, this values
are set at run-time)
if (objAtRow = "B" || objAtRow = "C" || objAtRow =
"X")
{
backBrush = new SolidBrush(Color.Red);
foreBrush = new SolidBrush(Color.White);
}
}
base.Paint(g, bounds, source, rowNum, backBrush,
foreBrush, alignToRight);
}
[/code]
My problem now is, how can I do this to the full row? At this stage I
know the row number, and the cell, but I don't have any access to the
cells that exist in the same row :( (or do I?)
Any ideas? I just cannot figure out how to do this...
Thanks ahead for all the help.
Best Regards,
L. Pinho
Trust Me; I'm from the government - 26 Sep 2007 19:52 GMT
Use the GridViewRowEventArgs event
I realize you're a C# guy, and the sample I'm going to show you is VB.Net,
but it should point you in the correct direction:
http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=GVConditionalRowC
oloring
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
> Hi,
>
[quoted text clipped - 39 lines]
>
> L. Pinho
dreamkeys@gmail.com - 27 Sep 2007 09:25 GMT
On Sep 26, 7:52 pm, "Trust Me; I'm from the government"
<s...@here.com> wrote:
> Use the GridViewRowEventArgs event
> I realize you're a C# guy, and the sample I'm going to show you is VB.Net,
[quoted text clipped - 50 lines]
>
> > L. Pinho
Hi,
thanks for the reply
I'm trying to do this at a windows forms level, I don't seem to find
the DoColor event/method anywhere, is a part of which object?
Thanks
Bob Powell [MVP] - 30 Sep 2007 13:14 GMT
This can be accomplished by handling the RowPrePaint event and setting the
background color of the cell accordingly.
void dataGridView1_RowPrePaint(object sender,
DataGridViewRowPrePaintEventArgs e)
{
if(e.RowIndex>-1)
{
someclass sc = (someclass)dataGridView1.Rows[e.RowIndex].DataBoundItem;
this.dataGridView1.Rows[e.RowIndex].Cells[0].Style.BackColor = sc.Color;
}
}

Signature
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
> Hi,
>
[quoted text clipped - 39 lines]
>
> L. Pinho