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 

Back Color

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





PostPosted: Mon Dec 05, 2005 9:01 am    Post subject: Back Color Reply with quote

I have a BackColor problem as follows.

Once you specify the BackColor of RowBinding and its cell bindings , they remain fixed for that level. I have 3 levels ( Level1,Level2,Level3). In the “DataBindings” tab I have specified the BackColor for each of them. Now when the Grid comes up,the Level1,Level2,Level3 rows will be colored as specified.

What I want is that even in Level1, I want to specify different color for each row. Is this possible?

Let’s say I have 10 Level1 rows. Now I want to specify a different color for each of these Level1 rows. Can this be done?
If yes please brief me how to achieve this?

Thanks in advance
Shailendra
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Dec 05, 2005 10:00 am    Post subject: Reply with quote

There are already several other threads about this. To summarize:

If there are a fixed number of different styles that you want to apply then the best way to do this is to create a separate RowBinding for each type of row and set up the styles (colors etc) in the RowBindings editor. Then you can handle the GetBinding event (or override the GetRowBinding method) to select the row binding (and hence visual style) to use based on the item properties.

An alternative is to handle the GetRowData and GetCellData events (or override the corresponding methods) and set the OddStyle and EvenStyle properties of the CellData/RowData programmatically. Note that because rows share references to styles (to conserve resources) you can't just set the BackColor of the existing style - as this will change the colors of all rows using that style. Instead you need to assign a separate style. You can create new styles on the fly in the GetRowData/GetCellData methods eg

Code:
 
private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
    // get the default settings using the row binding
    //
    RowBinding binding = _virtualTree.GetRowBinding(e.Row);
    binding.GetCellData(e.Row, e.Column, e.CellData);

    // check if you want to highlight this item
    //
    if (e.Row.Item == "A")
   {
        Style highlightStyle = new Style(_virtualTree.RowStyle);
        highlightStyle.BackColor = Color.Red;
        e.CellData.OddStyle = highlightStyle;
        e.CellData.EvenStyle = highlightStyle;
    }
}


This has the performance disadvantage that you are creating new styles all the time - so it would be better to setup the style at initialization in a member variable if possible and then just assign it in the GetCellData/GetRowData events.
_________________
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