Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setting foreground colours in individual cells

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
keesp
Guest





PostPosted: Tue Jun 07, 2005 11:37 am    Post subject: Setting foreground colours in individual cells Reply with quote

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

PostPosted: Tue Jun 07, 2005 11:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
flc.net



Joined: 21 Jun 2005
Posts: 89
Location: Switzerland

PostPosted: Wed Jun 22, 2005 12:28 pm    Post subject: Bug? Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jun 22, 2005 11:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group