Event on checked TreeView node?

  • Thread starter Thread starter Brett Romero
  • Start date Start date
B

Brett Romero

How can I take action when a particular child node is
checked/unchecked?

Root1
-A1
-A2
-A3
Root2
-B1
-B2
-B3
Root3
-C1
-C2
-C3
If any of the check nodes are checked/unchecked, I'd like to know and
take action.

Thanks,
Brett
 
Look at the .BeforeChecked and .AfterChecked events on the tv

Marc
 
Thanks. I have it working now:

if( e.Node.Name.Equals( "MyNodeName" ) )
{
if( e.Node.Checked )
//do something
else
//do something else
}

This will get unruly with say seven root nodes and 10 child nodes each.
Is there a better way to manage it?

Thanks,
Brett
 
It really depends on what the rules are about when you select which
node(s)... that has to come from somewhere...

Thoughts: you could always build a dictionary of what-to-do-for-each...
either using the Name property (e.g. Dictionary<string, MethodInvoker>)
or (if it will work correctly) the object reference
(Dictionary<TreeNode, MethodInvoker>). Or something else along these
lines...

Dictionary<string,MethodInvoker> dict = new ....blah
dict.Add("NodeNameA", delegate {DoSomethingFunky(params,
moreParams);});
dict.Add("NodeNameB", SomeMethod);
//...
// then in the event handler
MethodInvoker mi;
if(dict.TryGetValue(e.Node.Name, out mi) && mi!=null) mi(); // or
mi.Invoke();

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top