View previous topic :: View next topic |
Author |
Message |
Mark Johnson Guest
|
Posted: Wed Mar 09, 2005 10:22 pm Post subject: Collapsed node event? |
|
|
Is there an event to find out the user collapsed a node in the tree?
The scenario is I need to change selection to the node that is collapsed if the currently selected row is under that node in the tree.
Thanks,
Mark |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Mar 10, 2005 5:13 am Post subject: |
|
|
There is currently no event to notify you of this (since generally VirtualTree handles obtaining data on demand - which this what the expand/collapse events of other trees are typically used for).
You can however achieve what you want by using the widget framework to change the behaviour of the "ExpansionWidget" (see the section in the online help on "Custom Painting and Mouse Handling" under "Customizing Appearance" for more information)
To do this you derive a new ExpansionWidget class as follows:
Code: |
using Infralution.Controls.VirtualTree;
public class MyExpansionWidget : ExpansionWidget
{
public MyExpansionWidget(RowWidget rowWidget)
: base(rowWidget)
{}
public override void OnMouseDown(MouseEventArgs e)
{
RowWidget.OnMouseDown(e);
base.OnMouseDown (e);
}
}
|
This will change the behaviour of the expansion widget so that when you expand/collapse a row that row is selected (since that is the default behaviour of RowWidget.OnMouseDown - we just let it handle it)
Then you inherit from VirtualTree to override the method that creates the expansion widget as follows:
Code: |
using Infralution.Controls.VirtualTree;
public class MyVirtualTree : VirtualTree
{
protected override ExpansionWidget
CreateExpansionWidget(RowWidget rowWidget)
{
return new MyExpansionWidget(rowWidget);
}
}
|
If you really feel a Collapse/Expand event is needed let us know and we will consider it for a future release. _________________ Infralution Support
Last edited by Infralution on Tue Apr 05, 2005 9:01 am; edited 1 time in total |
|
Back to top |
|
|
Mark Johnson Guest
|
Posted: Mon Mar 14, 2005 6:23 pm Post subject: |
|
|
Thanks for the response.
That's close to what I want.
I specifcally need to only select the collapsed node if the currently selected node is a child of the node being collapsed. So the user has to always have an item selected that is not collapsed. I don't need to do anything on expanding, just collapsing.
Thanks,
Mark |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Mar 14, 2005 9:28 pm Post subject: |
|
|
You could change the OnMouseDown method to only call the RowWidget.OnMouseDown method if the currently selected row (if any) is a child of the row and the row is expanded eg:
public override void OnMouseDown(MouseEventArgs e)
{
if (this.Row.Expanded)
{
Row selectedRow = Tree.SelectedRow;
if (selectedRow != null && selectedRow.ParentRow == this.Row)
{
RowWidget.OnMouseDown(e);
}
}
base.OnMouseDown (e);
}
This assumes you a using single selection mode. If you are using multiple selection you would need to check each row in the SelectedRows. _________________ Infralution Support |
|
Back to top |
|
|
Mark Johnson Guest
|
Posted: Tue Mar 15, 2005 5:59 pm Post subject: |
|
|
Thanks for the help.
I end up getting it to work. |
|
Back to top |
|
|
|