View previous topic :: View next topic |
Author |
Message |
GreyCloud
Joined: 13 Nov 2008 Posts: 19
|
Posted: Mon Oct 18, 2010 8:35 am Post subject: expand last sibling of focused node |
|
|
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();
}
| |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Oct 18, 2010 10:00 pm Post subject: |
|
|
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 |
|
|
|