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 

hight lighting the ancestor rows of the selected row

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



Joined: 19 Jan 2007
Posts: 44

PostPosted: Mon Sep 24, 2007 4:37 pm    Post subject: hight lighting the ancestor rows of the selected row Reply with quote

We are setting EnsureVisible to false when a node is selected, but we would like to hightlighting (change background color as light green) all it's ancestors, so user will know where the selected node might located. Could you show us how can we do it? Thanks.
Back to top
View user's profile Send private message
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Mon Sep 24, 2007 4:59 pm    Post subject: change selection color Reply with quote

the default selection color is blue, and in some of computers, it become very dark blue, how can we change the selection color?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Sep 24, 2007 11:14 pm    Post subject: Reply with quote

Quote:
how can we change the selection color?


Set the RowSelectedStyle.BackColor

Quote:
We are setting EnsureVisible to false


I'm not sure what you mean by this? EnsureVisible is a method not a bool property.

Quote:
but we would like to hightlighting (change background color as light green) all it's ancestors, so user will know where the selected node might located. Could you show us how can we do it?


Do you mean that whenever a row is selected you want to highlight its ancestors - or do you mean that you will provide a button or menu which will allow the user to highlight the ancestors of the currently selected row?

The first option is probably fairly difficult to do efficiently. The second option is probably better. To do this you would need to programmatically handle the GetRowData and GetCellData events and for rows that are ancestors of the currently selected row you would set the Odd and Even Styles to a style with a different BackColor. See the FAQ on setting styles for cells for more information.

You can use the Row.IsDescendant method to determine whether a row is ancestor of the selected row. To force Virtual Tree to update the data an styles you need to call VirtualTree.UpdateRowData when the button is clicked. You could also do this whenever selection changes (to implement option 1) however there is a performance overhead to calling UpdateRowData everytime selection is changed.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Mon Sep 24, 2007 11:54 pm    Post subject: Reply with quote

Thanks.
Quote:
We are setting EnsureVisible to false

My mistake, I means we are not calling this method.

Quote:
Do you mean that whenever a row is selected you want to highlight its ancestors - or do you mean that you will provide a button or menu which will allow the user to highlight the ancestors of the currently selected row?


We would like to have the first option - whenever a row is selected you want to highlight its ancestors. We are providing the same behavior as Maya outliner in our application.
The Odd and Event Styles have been used for another purpose, beside Odd and Event Style, do we have any other option to change row's back color?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Sep 25, 2007 12:15 am    Post subject: Reply with quote

Quote:
The Odd and Event Styles have been used for another purpose, beside Odd and Event Style, do we have any other option to change row's back color?


This set me thinking - there is a better way to do what you want. You need to create a custom RowWidget and CellWidget class as follows:

Code:
    class RowWidgetEx : RowWidget
    {
        public RowWidgetEx(PanelWidget panel, Row row)
            : base(panel, row)
        {
        }

        public override Style GetActiveStyle()
        {
            Row selectedRow = Tree.SelectedRow;
            if (selectedRow != null && selectedRow.IsDescendant(Row))
                return GetSelectedStyle();
            else
                return base.GetActiveStyle();
        }
    }

    class CellWidgetEx : CellWidget
    {
        public CellWidgetEx(RowWidget rowWidget, Column column)
            : base(rowWidget, column)
        {
        }

        public override Style GetActiveStyle()
        {
            Row selectedRow = Tree.SelectedRow;
            if (selectedRow != null && selectedRow.IsDescendant(Row))
                return GetSelectedStyle();
            else
                return base.GetActiveStyle();
        }
    }


Then you need to set Virtual Tree to use these custom widgets - either by deriving a new class from VirtualTree and overriding CreateRowWidget and CreateCellWidget or by setting the RowWidgetCreator/CellWidgetCreator delegates.

The above assumes you have set AllowMultiSelect to false (ie only a single selection).
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
billcch



Joined: 19 Jan 2007
Posts: 44

PostPosted: Sun Jun 15, 2008 6:55 pm    Post subject: Reply with quote

Thanks. There is one issue, if SelectionMode is FullRow, your solution has no problem; but when SelectionMode is MainCellText, the cell back color won't change (only change row back color).
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Sun Jun 15, 2008 11:11 pm    Post subject: Reply with quote

This is because the logic for MainCellText selection mode is a bit different. If you are using this mode you will need to override the CellWidget.PaintForeground method something like:

Code:
protected override void PaintForeground(Graphics graphics, Style style, bool printing)
{
    Row selectedRow = Tree.SelectedRow;
    if (selectedRow != null && selectedRow.IsDescendant(Row)&&!printing)
    {
        style = GetSelectedStyle();
        string text = Text;
        Rectangle textBounds = GetTextBounds();
        Rectangle selectBounds = GetActualTextBounds(graphics, textBounds, style, text);
        selectBounds.Inflate(style.BorderWidth, 0);
        PaintSelectedTextBackground(graphics, selectBounds, style);
    }
    base.PaintForeground(graphics, style, printing);
}


With this code you don't need to create a custom row widget or override the GetActiveStyle.
_________________
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