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 

Access CellData without using GetCellData event

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



Joined: 05 Jun 2007
Posts: 4

PostPosted: Tue Jun 05, 2007 4:14 pm    Post subject: Access CellData without using GetCellData event Reply with quote

I need to be able to change a cell's background color based on an event that occurs outside of the tree. So, the GetCellData never fires since the tree isn't involved in this external event.

When the external event occurs, I have access to the Row and I know which column the cell lies in, how can I retrieve the CellData from this information so that I can set the OddStyle/EvenStyle on the CellData object?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Jun 05, 2007 11:08 pm    Post subject: Reply with quote

Virtual Tree is data driven. This means the state of the tree is based on the underlying state of the data. The mapping between the data state and the display state is done by the GetCellData event. This avoids any possibility of the display state getting out of synch with the data state. If the underlying data changes in some way then you need to tell Virtual Tree to update its display state. If your data source supports the IListChanged interface then generally this happens automatically when the data is changed.

In your case you should call the UpdateRowData(row) to force Virtual Tree to fire the GetCellData event for that row.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
eheinz



Joined: 05 Jun 2007
Posts: 4

PostPosted: Wed Jun 06, 2007 3:46 pm    Post subject: Reply with quote

Works thanks.
Back to top
View user's profile Send private message
eheinz



Joined: 05 Jun 2007
Posts: 4

PostPosted: Wed Jun 06, 2007 4:24 pm    Post subject: Even/Odd style background color size Reply with quote

It seems when I set the background color for CellData using Even/Odd Style it sets the correct color, but the size of the color block equals the largest cell instead of performing similiar to the color block if I just select a cell.

When selecting a cell, the color block around the text (dark grey) is trimmed to match cell text. This same behavior is desired when I change the Even/Odd Style's background color on a cell.

Is that possible?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jun 06, 2007 10:32 pm    Post subject: Reply with quote

I assume you must be using SelectionMode of "MainCellText". In this mode only the cell text is highlighted when selecting. The Style backcolor however affects the whole of the cell. It would be possible to get the behaviour you want by creating a custom CellWidget and overriding the PaintBackground method - something like:

Code:
protected virtual void PaintBackground(Graphics graphics, Style rowStyle,
                                               Style cellStyle, bool printing)
{
    Rectangle bounds = GetActualTextBounds(graphics, GetTextBounds(),  style, Text);
    if (rowStyle.BackColor != cellStyle.BackColor)
    {
          cellStyle.DrawBackground(graphics, bounds);
     }
}


Note this assumes you are not using cell borders. If you want cell borders then you also need to draw them here. See the section in the online help about creating and using custom widgets.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
eheinz



Joined: 05 Jun 2007
Posts: 4

PostPosted: Thu Jun 07, 2007 1:46 pm    Post subject: Reply with quote

Is GetActualTextBounds part of your library or something I should create. I don't see this method in my version (2.5.4.0)
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Jun 07, 2007 10:23 pm    Post subject: Reply with quote

Sorry I assumed you were using version 3 of Virtual Tree (for VS2005). Version 2.5 does not have this method. You would need to implement it yourself - something like:

Code:
protected Rectangle GetActualTextBounds(Graphics graphics, Style style)
{
    Rectangle bounds = GetTextBounds();           
    string text = Text;
    SizeF size = style.MeasureString(graphics, Text, bounds.Width);
    bounds.width = size.Width;
    return bounds;
}


Note that the latest version for VS2003 is 2.7.0. Have you purchased Virtual Tree? If so you are able to upgrade to this for free. You can download it from our downloads page www.infralution.com/downloads.html.
_________________
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