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 

expand last sibling of focused node

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



Joined: 13 Nov 2008
Posts: 19

PostPosted: Mon Oct 18, 2010 8:35 am    Post subject: expand last sibling of focused node Reply with quote

i'd like to expand the last sibling of the focused node - why does the following throw an index out of range exception?

Code:

 this.Tree.FocusRow.Expand();
                                            if (this.Tree.FocusRow.ParentRow != null) {
                                                ((Row)
                                                 this.Tree.FocusRow.ParentRow.ChildItems[
                                                     this.Tree.FocusRow.ParentRow.LastChildRowIndex]).Expand();
                                            }
Shocked
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Oct 18, 2010 10:00 pm    Post subject: Reply with quote

There are two problems with your code. The first is that "LastChildRowIndex" returns the absolute index (ie the RowIndex) within the whole tree of the last child. It doesn't return the local child index of the child. You could get the local child index via ChildItems.Count-1. The second issue is that the ChildItems IList is a list of the underlying data objects - not Row objects. So even if you had the right index the cast to a Row would fail.

Below is some code that will do what you want. It uses the Tree.GetRow function which takes the absolute RowIndex to get the row to expand.

Code:
Row focusRow = this.Tree.FocusRow;
Row parentRow = focusRow.ParentRow;
focusRow.Expand();
if (parentRow != null)
{
    Row siblingRow = this.Tree.GetRow(parentRow.LastChildRowIndex);
    if (siblingRow != null)
    {
        siblingRow.Expand();
    }
}

_________________
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