Comments
4 comments
-
I would try the TreeView's ExpandAll() method - you might have to explicitly cast to a TreeView first.
-
Hello haleyjason,
thanks for your response.
I’m doing the explicit cast of the TreeView
Anyway, I prefer to show you the entire code
Note: This project have 2 main items.
1 - Package Class: To comunicate with the Reflector
2 - MethodForm:
Package Class
internal class MethodDependencyPackage : IPackage
{
private IWindowManager windowManager;
private ICommandBarManager commandBarManager;
private ICommandBarSeparator separator;
private ICommandBarButton button;
public void Load(IServiceProvider serviceProvider)
{
MethodDependencyWindow methodDependencyWindow = new MethodDependencyWindow();
this.windowManager = (IWindowManager)serviceProvider.GetService(typeof(IWindowManager));
this.windowManager.Windows.Add("MethodDependencyWindow", methodDependencyWindow, "Method Dependency");
//obtengo la ventana de Analyzer
methodDependencyWindow.windowsAnalyzer = this.windowManager.Windows["AnalyzerWindow"];
this.commandBarManager = (ICommandBarManager)serviceProvider.GetService(typeof(ICommandBarManager));
this.separator = this.commandBarManager.CommandBars["Tools"].Items.AddSeparator();
this.button = this.commandBarManager.CommandBars["Tools"].Items.AddButton("&MethodDependency", new EventHandler(this.MethodDependencyButton_Click));
}
}
}
In this class I get the Analyzer window object. I will need it to get the TreeView and expand it.
When the first node is expanded the MethodDependencyAfterExpand is called and begins the recursion
the problem I see, is that, the second time that the MethodDependencyAfterExpand is called, the actual node (e.Node) has no childNodes (e.Node.Nodes.Count =0 )
windowFormClass
public partial class MethodDependencyWindow : UserControl
{
private IWindow _windowsAnalyzer;
public IWindow windowsAnalyzer
{
get { return _windowsAnalyzer; }
set {
_windowsAnalyzer = value;
TreeView analyzerTreeView = (TreeView)(windowsAnalyzer.Content.Controls[0]);
analyzerTreeView.AfterExpand += new TreeViewEventHandler(this.MethodDependencyAfterExpand);
}
}
private void MethodDependencyAfterExpand(object sender, TreeViewEventArgs e)
{
System.Threading.Thread.Sleep(2000);
foreach (TreeNode node in e.Node.Nodes)
{
if (node.Parent != null && node.Parent.IsExpanded)
{
node.Expand();
}
}
}
}
Regards,
Nico -
I think you can probably come up with something using 2 different events and the producer consumer pattern of sorts. The 2 events i would try are the AfterExpanded (which you have) and the Invalidated (which will fire when the next node is ready).
private void tree_Invalidated(object sender, InvalidateEventArgs e) { MessageBox.Show("Invalidated"); }
private void MethodDependencyAfterExpand(object sender, TreeViewEventArgs e) { if (e.Action == TreeViewAction.Expand) { MessageBox.Show("After Expanded"); } }
I was thinking something like the following would work:
1. expand a node and throw any children in a queue/list for processing (producer)
2. have a consumer of that queue/list that looks for nodes it should expand (the consumer will need to be wired to the queue/list so it knows when to process new items)
3. when the invalidated event fires, check for new nodes and put into queue/list to be processed
4. when expanded event fires, check for new nodes and put into queue/list to be processed
Play around with the timing of those 2 events and you'll probably find what you need to know when to try and exapand a node once it is available.
Buena Suerta -
Hi all,
Finally did you succeed ?
I'm trying todo the same thing, I have no real error. but Reflector doesn't respond anymore after.
The first node i expand is ok, the second is not.
Can you help me?
Thanks
Jérôme
Add comment
Please sign in to leave a comment.
I'm developing an add-in to .Net Reflector and I need to expand all the nodes in the windowsAnalyzer TreeView by code. I tried to do it recursively using the expand() method but when the recursion expands the second level stops there becouse (I think) the node Isn't properly loaded. My code is something like:
analyzerTreeView.AfterExpand += new TreeViewEventHandler(this.MethodDependencyAfterExpand);
private void MethodDependencyAfterExpand(object sender, TreeViewEventArgs e)
{
foreach (TreeNode node in e.Node.Nodes)
{
node.Expand();
}
}
Can someone help me to make it work?
thanks!
Nico