DataGrid Row Colours
-
Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au
-
Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au
If you have a web form, override the ItemDataBound event. Peter Molnar
-
If you have a web form, override the ItemDataBound event. Peter Molnar
Hi, It is a Windows form control :) Web design and hosting http://www.kayess.com.au
-
Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au
This shows you how to backgroud of each cell. I think there is another article in CP that helps you to change whole color of row: http://www.codeproject.com/csharp/custom_datagridcolumnstyl.asp[^] Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji -
Hi All, Is it possible to have the colour of a Datagrid row different from the other rows depending on the value in one of the cells. For example if I have a list of products and prices can I make the row highlighted red if the price is 0.00 If so how do I go about doing it? Thanks Web design and hosting http://www.kayess.com.au
In your form class after you added the grid to the form add:
DataGridColoredRowColumn aTextColumn; for (int i = 1; i < numColumns; i++) { aTextColumn = new DataGridColoredRowBoxColumn ();} this.datagridStyle.GridColumnStyles.Add(aTextColumn);
Add a new class DataGridColoredRowBoxColumn, in which you will override the paint method.public class DataGridColoredRowBoxColumn : DataGridTextBoxColumn { 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) { try { object o = this.GetColumnValueAtRow(source, rowNum); if( o!= null) { string str = (string)o; if (str == "WHATEVER YOU COMPARE TOO") { backBrush = new SolidBrush(Color.Pink); } } catch (Exception) {} finally { base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); } } }