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 

Style property on CellData and RowData?

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



Joined: 04 Apr 2005
Posts: 69

PostPosted: Fri Apr 08, 2005 12:15 pm    Post subject: Style property on CellData and RowData? Reply with quote

It would be nice to be able to override the base style for a given row or cell, but CellData and RowData only have properties for the even, odd, selected and print styles separately. That makes it a bit tedious to change the appearance of an item programmatically, applying a delta to each of the properties. Is there another way?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Apr 12, 2005 10:51 pm    Post subject: Reply with quote

Using RowBindings makes this easy - because you can set all this stuff visually. It is worth considering using Object bindings - even if you only set up the visual stuff using them - and do every thing else programmatically.

Your OnGetCellData method can then just assign the properties from the binding eg

Code:

protected override void OnGetCellData(Row row, Column column, CellData cellData)
{
    cellData.OddStyle = _myCellBinding.OddStyle;
    cellData.EvenStyle = _myCellBinding.EvenStyle;
    cellData.SelectedStyle = _myCellBinding.SelectedStyle;
}


If you aren't wanting to change the default style for cell (which is set in the column) then you don't need do this.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
MHB



Joined: 04 Apr 2005
Posts: 69

PostPosted: Fri Apr 15, 2005 9:02 am    Post subject: Reply with quote

I do use RowBindings, and I did override OnGetCellData because I only wanted to deviate from the default style under certain circumstances, based on runtime information.

My point was exactly what you exemplified here - I have to assign 3 different members instead of just one base style.

Actually, in my situation I just wanted to change some text to bold, and in order to do this (and nothing else), I have to code these 9 lines, a bit excessive looking to me:

Code:

Infralution.Controls.StyleDelta deltaEven = new Infralution.Controls.StyleDelta();
Infralution.Controls.StyleDelta deltaOdd = new Infralution.Controls.StyleDelta();
Infralution.Controls.StyleDelta deltaSelected = new Infralution.Controls.StyleDelta();
deltaEven.Font = new System.Drawing.Font(cellData.EvenStyle.Font, System.Drawing.FontStyle.Bold);
deltaOdd.Font = new System.Drawing.Font(cellData.OddStyle.Font, System.Drawing.FontStyle.Bold);
deltaSelected.Font = new System.Drawing.Font(cellData.SelectedStyle.Font, System.Drawing.FontStyle.Bold);
cellData.EvenStyle = new Infralution.Controls.Style(cellData.EvenStyle, deltaEven);
cellData.OddStyle = new Infralution.Controls.Style(cellData.OddStyle, deltaOdd);
cellData.SelectedStyle = new Infralution.Controls.Style(cellData.SelectedStyle, deltaSelected);
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sun Apr 17, 2005 11:36 pm    Post subject: Reply with quote

Maybe you missed my point. If you create an object binding using the virtual tree editor you can select the CellBinding and set the font to bold for odd, even and selected cells by setting the font in the base "Style" property. This is because row and cell bindings set up a style hierarchy similar to what you originally were asking for.

You can then programmatically determine whether or not to use the cellBinding with the bold font. This only takes the three lines of code I used before. In fact you could do it in one line of code:

Code:

if (shouldbeBold)
{
    this._boldBinding.GetCellData(row, column, cellData) 
}


However this is not quite so efficient since it also sets the cellData.Value the Editor and other stuff. It is however probably much more efficient then your example code which creates a whole bunch of new styles and fonts each time OnGetCellData is called.

Note that the cell binding styles are parented by the column style not the row binding style. So changing a row binding style property will not flow onto to each cell in that row. This is because we felt it would be more useful (and typical) to be able to change the style properties of all cells in a column in one place - and it is just too complicated (for the user and us) to try and create some form of dual parenting from column and row binding styles.

If you are really allergic to using the visual designer then you could still code the require styles more efficiently as follows:

Code:

StyleDelta boldDelta = new StyleDelta();
boldDelta.Font = new Font(cellData.EvenStyle.Font, FontStyle.Bold);
cellData.EvenStyle = new Style(cellData.EvenStyle, boldDelta);
cellData.OddStyle = new Style(cellData.OddStyle, boldDelta);
cellData.SelectedStyle = new Style(cellData.SelectedStyle, boldDelta);


This still has the performance disadvantage of creating new styles and fonts each time OnGetCellData is called. I would be more inclined to create the styles upfront and store them in member variables - which is what RowBindings and CellBindings do. VirtualTree provides a method which can be overriden to do this eg:

Code:

        protected override void InitializeStyles()
        {
            base.InitializeStyles ();
            StyleDelta boldDelta = new StyleDelta();
            boldDelta.Font = new Font(this.RowStyle.Font, FontStyle.Bold);
            _boldEvenStyle = new Style(this.RowEvenStyle, boldDelta);
            _boldOddStyle = new Style(this.OddStyle, boldDelta);
            _boldSelectedStyle = new Style(this.SelectedStyle, boldDelta);
        }

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
MHB



Joined: 04 Apr 2005
Posts: 69

PostPosted: Mon Apr 18, 2005 9:27 am    Post subject: Reply with quote

Thanks for those pieces of information, it's good to know exactly what inheritance relationships exist. However, I think you missed my point! So far, my case is rather simple, and any of these options are usable. But if I only want to change one property of the default style for one particular cell (no matter what row or column style it may derive from), instead of creating a complete new style and setting all properties, it still looks like I have to do it the complicated way, generating new styles on demand. Otherwise I may accidentally override more properties than I intended. Your suggestions require that I at coding time create a specific static style to use for each and every possible combination that may occur at runtime. This may become an issue if the application gets more complicated, with lots of different bindings and special cases. I'm not requesting multiple inheritance, just the possibility of using a style delta to override specific properties at cell level (maybe also row level). I may however also be overshooting the mark here, and trying to obtain more theoretical generality than what's actually necessary...
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Apr 18, 2005 9:51 am    Post subject: Reply with quote

OK I understand a little better what you are trying to do. If you really can't determine a fixed set of styles at design time then you have to fall back to creating them in the OnGetCellData method. You could still use my slightly more compact code where you apply the same Style delta to each of the three styles.

The reason there is not a parent child relationships between a base style and the styles in the CellData is performance related. In general 99% of users will use the bindings to manage styles (even if they are using programmatic data binding for everything else). The default odd, even and selected styles set in the CellData are just the VirtualTree RowOddStyle, RowEvenStyle and RowSelected style respectively. To set up a base style and parent the CellData styles from it would require creating four new styles and applying the relevant style delta(s) from the VirtualTree base styles (so that you are still able to change the base VirtualTree odd, even and selected styles and have those changes apply to rows where you may have changed the CellData.Style properties).

This is all fairly complicated and would be totally redundant if you are using row bindings - as these set up these types of style relationships. It is also a performance hit in a method which is called with a high frequency.

In summary I would reconsider whether you really do need the generality - but if you do then I'm afraid we probably can't reduce the number of lines required to write it - hopefully you only need to do it once.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
MHB



Joined: 04 Apr 2005
Posts: 69

PostPosted: Mon Apr 18, 2005 10:34 am    Post subject: Reply with quote

Ah, it's a performance issue. I wouldn't have thought it was, but in that case it probably isn't worth it to generalize further. I've already changed my approach to using different objects and row bindings. It's just that this is not straight forward to do without a performance hit - the data I'm displaying is transmitted over the Internet. Originally I just needed non-leaf nodes to appear bold, and network-wise that was more efficient to do at runtime during style selection, due to the implementation of the data source. Now I'm looking into changing the way the data source works accordingly.
Back to top
View user's profile Send private message
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