View previous topic :: View next topic |
Author |
Message |
Mrdec
Joined: 04 May 2006 Posts: 7
|
Posted: Thu May 04, 2006 10:55 am Post subject: Different style for each cell |
|
|
Hello,
I use programmatic data binding and I need different appearances of rows that are bound to the same item type. I intuitively tried to set e.CellData.Style by there is not property like this. However there are properties e.CellData.EvenStyle/OddStyle, but these properties modify cell style of all rows instead of to modify only style of the processing cell. How should I solve this problem, could you help me please?
Code: | private void tree_GetCellData(object sender, GetCellDataEventArgs e)
{
if (e.Row.Item is MyItem)
{
MyItem item = (e.Row.Item as MyItem);
e.CellData.Value = item.Value;
if (item.Active) e.CellData.Style.ForeColor = Color.Red; // I expected Style property
}
} |
|
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu May 04, 2006 10:42 pm Post subject: |
|
|
You can't just set the color property of the style - this will set the color of all cells that use this style (which by default is every cell in the tree). If you want a cell to have a different color then you need to assign it a new (or different) Style. For example in GetCellData you could do:
Code: |
Style highlightStyle = new Style(cellData.OddStyle);
highlightStyle.Color = Color.Red;
cellData.EvenStyle = highlightStyle;
cellData.OddStyle = highlightStyle;
|
If you know upfront what colors/styles you need it would be better for performance to create the highlight style in your constructor and just do the assignments in GetCellData. _________________ Infralution Support |
|
Back to top |
|
|
Mrdec
Joined: 04 May 2006 Posts: 7
|
Posted: Thu May 04, 2006 11:02 pm Post subject: |
|
|
Thanks, it works fine |
|
Back to top |
|
|
|