DataTable - DataGrid
-
Ok, i have a DataTable with some columns, and i have a DataGrid. The DataGrid DataSource is my DataTable. So, how i color some elements? I want to color all elements in the Table = "F" and "I" Thanks. :)
the following article in CP, will guide you in achieving the goal Changing the background color of cells in a DataGrid Please revert back whether you could achieve the functionality or not? Regards, Jay
-
the following article in CP, will guide you in achieving the goal Changing the background color of cells in a DataGrid Please revert back whether you could achieve the functionality or not? Regards, Jay
-
I dont know, im not using Colum or table styles, just DataSource. I Want color a element on a cell. I have a DataTable with some columns, and call this table in DataSource.
1.To do this you first have to create class derived from
DataGridTextBoxColumn
orDataGridColumnStyle
. You then have to override thePaint()
method of these classes. Implement the Paint Method as belowprotected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight) { string val = (string) GetColumnValueAtRow(source, rowNum); if(val == "T") foreBrush = Brushes.Green; else if (val == "F") foreBrush = Brushes.Red; base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); }
2. You will have to use
DataGridColumnStyle
to achieve the functionality. 3. Read the article, I had given you in my previuos reply. also download and run the sample project of the article. This will help you a lot. Regards, Jay. -
I dont know, im not using Colum or table styles, just DataSource. I Want color a element on a cell. I have a DataTable with some columns, and call this table in DataSource.
You're need to. It's not hard - just see the
DataGrid.TableStyles
property in the .NET Framework SDK documentation. If you don't, you can't. The other reply is correct in what you must do.Microsoft MVP, Visual C# My Articles