ClayB
Fri Jun 04 19:08:36 CDT 2004
You can download sample projects using the technique suggested in the prior
post in this FAQ.
How do I color a individual cell depending upon its value or some external
method?
Check it out at:
http://www.syncfusion.com/faq/winforms/search/745.asp
=============================================
Clay Burch, .NET MVP
Syncfusion, Inc.
visit
http://www.syncfusion.com for .NET Essentials
"JStewart" <jstewart20042001@yahoo.com> wrote in message
news:cx6wc.16891336$Of.2810558@news.easynews.com...
>
> "toysrwill" <ldybug@peoplepc.com> wrote in message
> news:f57bd0a2.0406041255.52a857f1@posting.google.com...
> > Is it possible to make a single cell with its contents be in red color
> > while the rest of the datagrid is of normal color. If so how?
> > Thanks in advance
> > Will
>
> You can override the DataGridTextBoxColumn and in the OnPaint method you'd
> assign red as the foreground. You would need to supply the logic as to
which
> cells you keep as default and which you change, likely from the cell's
> contents.
>
> public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
> {
> protected override void Paint(System.Drawing.Graphics g,
> System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
> source, int rowNum, System.Drawing.Brush backBrush,
System.Drawing.Brush
> foreBrush, bool alignToRight)
> {
>
> try
> {
> object o = this.GetColumnValueAtRow(source, rowNum);
> if( o!= null)
> {
> //o is a reference to the cell's contents
> //you can modify the backBrush and foreBrush to whatever color
> you want
> foreBrush = new SolidBrush(Color.Red);
> }
> }
> }
> catch(Exception ex)
> {
> ex.ToString();
> }
> finally
> {
> //Paint the string
> base.Paint(g, bounds, source, rowNum, backBrush,
> foreBrush,alignToRight);
> }
> }
> }
>
>