View previous topic :: View next topic |
Author |
Message |
keesp Guest
|
Posted: Tue Jun 07, 2005 11:37 am Post subject: Setting foreground colours in individual cells |
|
|
Hi,
I seem to be having some problems setting the foreground colours of individual cells. If, in the getCellData method of a cell binding object I implement:
this.Style.ForeColor = node.ForeColor;
then nothing happens. If I make this:
this.Style.ForeColor = node.ForeColor;
cellData.EvenStyle.ForeColor = this.Style.ForeColor;
cellData.OddStyle.ForeColor = this.Style.ForeColor;
then ALL the rows turn to the node.ForeColor of the node that was last added...
So what am I missing here...?
Thanks,
Kees |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jun 07, 2005 11:10 pm Post subject: |
|
|
The VirtualTree.GetCellData method gets references to the style objects to use for a cell (the Odd, Even and Selected styles contained in CellData).
Changing a property of a style will therefore change any other cells that also reference the same style. This means that if you want two cells to have a different appearance then GetCellData needs to return references to two different style objects.
There are two ways of achieving this:
1. Create two row separate row bindings (with cell bindings) and setup the styles as you want then override the GetBinding method (or handle the GetBindingForItem event) to programmatically select the appropriate row binding for the appearance you want eg
Code: |
public override RowBinding GetRowBinding(object item)
{
if (ShouldBeRed(item))
{
return _redRowBinding;
}
return base.GetRowBinding(item);
}
|
2. Dynamically create new odd,even and selected styles in the GetCellData method by applying a StyleDelta to the default styles eg
Code: |
StyleDelta delta = new StyleDelta();
delta.ForeColor = Color.Red;
cellData.EvenStyle = new Style(cellData.EvenStyle, delta);
cellData.OddStyle = new Style(cellData.OddStyle, delta);
cellData.SelectedStyle = new Style(cellData.SelectedStyle, delta);
|
The thread "Style property on CellData and RowData?" has more detail on this. _________________ Infralution Support |
|
Back to top |
|
|
flc.net
Joined: 21 Jun 2005 Posts: 89 Location: Switzerland
|
Posted: Wed Jun 22, 2005 12:28 pm Post subject: Bug? |
|
|
Hi VirutalTree Team
I have the same needs, so i tried to set different back colors for invidual cells.
Instead of inherit virtual tree and override the OnGetCellData Method, I decided to listen to the event "GetCellData". After Adding an EventHandler (without Code) the Grid is empty.
Is this a Bug?
Best Regards
Giuseppe |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Jun 22, 2005 11:27 pm Post subject: |
|
|
No this isn't a bug. If you add an event handler to the GetCellData event (or any of the other data events) then you take responsibility for populating the CellData. So if you do nothing then the cells will be empty.
If you just want to do the default processing normally done by the bindings and then make some changes you can do this by adding the following in your event handler:
Code: |
RowBinding binding = _virtualTree.GetRowBinding(e.Row.Item);
binding.GetCellData(e.Row. e.Column, e.CellData);
|
_________________ Infralution Support |
|
Back to top |
|
|
|