Reputation: 1629
So in my documentation it says:
public event TreeViewPlusNodeCheckedEventHandler NodeChecked()
You can use this event to run cause a method to run whenever the check-box for a node is checked on the tree.
So how do I add a method to my code behind file that will run when a node is checked? The method I want to run is:
protected void TOCNodeCheckedServer(object sender, TreeViewPlusNodeEventArgs args)
{
TreeViewPlusNode aNode = args.Node;
if (!aNode.Checked)
return;
List<string> BaseLayers = new List<string>();
_arcTOCConfig.BaseDataLayers.CopyTo(BaseLayers);
List<MapResourceItem> mapResources = new List<MapResourceItem>();
if (BaseLayers.Contains(aNode.Text))
{
foreach (BaseDataLayerElement anEl in _arcTOCConfig.BaseDataLayers)
{
if (!aNode.Text.Equals(anEl.Name))
{
if (aNode.TreeViewPlus.Nodes.FindByValue(anEl.Name).Checked)
{
aNode.TreeViewPlus.Nodes.FindByValue(anEl.Name).Checked = false;
aNode.TreeViewPlus.Nodes.FindByValue(anEl.Name).Refresh();
MapResourceItem aMapResource = this.Map1.MapResourceManagerInstance.ResourceItems.Find(anEl.Name);
aMapResource.DisplaySettings.Visible = false;
this.Map1.RefreshResource(anEl.Name);
mapResources.Add(aMapResource);
this.Map1.MapResourceManagerInstance.ResourceItems.Remove(aMapResource);
}
else
{
MapResourceItem aMapResource = this.Map1.MapResourceManagerInstance.ResourceItems.Find(anEl.Name);
mapResources.Add(aMapResource);
this.Map1.MapResourceManagerInstance.ResourceItems.Remove(aMapResource);
}
}
}
foreach (MapResourceItem aMapResource in mapResources)
{
int count = this.Map1.MapResourceManagerInstance.ResourceItems.Count - 1;
this.Map1.MapResourceManagerInstance.ResourceItems.Insert(count, aMapResource);
this.Map1.MapResourceManagerInstance.CreateResource(aMapResource);
}
this.Map1.InitializeFunctionalities();
this.Map1.Refresh();
}
}
vs 2008 c# .net 3.5
Upvotes: 0
Views: 492
Reputation: 3140
On your initialise method for the form add
TOCTree.NodeChecked += new TreeViewPlusNodeCheckedEventHandler (TOCNodeCheckedServer);
This will tell your app to run TOCNodeCheckedServer when the TOCNode Fires the NodeChecked Event.
There are loads of resources on the web explaining how this works. Check out http://www.csharphelp.com/archives/archive253.html as an example.
Upvotes: 0
Reputation: 15772
This is a standard case of registering a handler for an event
treeView.NodeChecked += TOCNodeCheckedServer;
Upvotes: 2
Reputation: 12509
Just add a handler to the event.
myTreeView.NodeChecked += new TreeViewPlusNodeCheckedEventHandler(TOCNodeCheckedServer);
or (because instantiating the TreeViewPlusNodeCheckedEventHandler isn't actually necessary)
myTreeView.NodeChecked += TOCNodeCheckedServer;
Upvotes: 2
Reputation: 4607
You need to assign a delegate to the event and have it run the method you want. Something like :
TreeViewControl.NodeChecked += new TreeViewPlusNodeCheckedEventHandler(TOCNodeCheckedServer)
Upvotes: 5