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

Re: Set the row background color according to a cell value by Trust

Trust
Wed Sep 26 11:52:50 PDT 2007

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=GVConditionalRowColoring

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


<dreamkeys@gmail.com> wrote in message
news:1190825822.923105.60780@22g2000hsm.googlegroups.com...
> 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
>



Re: Set the row background color according to a cell value by dreamkeys

dreamkeys
Thu Sep 27 01:25:14 PDT 2007

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,
> but it should point you in the correct direction:http://www.aspnet101.com/aspnet101/aspnet/codesample.aspx?code=GVCond...
>
> David Wierhttp://aspnet101.comhttp://iWritePro.com- One click PDF, convert .doc/.rtf/.txt to HTML with no
> bloated markup
>
> <dreamk...@gmail.com> wrote in message
>
> news:1190825822.923105.60780@22g2000hsm.googlegroups.com...
>
> > 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

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


Re: Set the row background color according to a cell value by Bob

Bob
Sun Sep 30 05:14:52 PDT 2007

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;

}

}


--
--
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.


<dreamkeys@gmail.com> wrote in message
news:1190825822.923105.60780@22g2000hsm.googlegroups.com...
> 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
>