所以在我的文档中它说:
公共事件TreeViewPlusNodeCheckedEventHandler NodeChecked()
您可以使用此事件运行,只要在树上检查节点的复选框,就会运行方法.
那么如何在我的代码后面添加一个方法,该方法将在检查节点时运行?我想要运行的方法是:
protected void TOCNodeCheckedServer(object sender, TreeViewPlusNodeEventArgs args) { TreeViewPlusNode aNode = args.Node; if (!aNode.Checked) return; ListBaseLayers = new List (); _arcTOCConfig.BaseDataLayers.CopyTo(BaseLayers); List mapResources = new List (); 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
您需要为该事件分配一个委托,并让它运行您想要的方法.就像是 :
TreeViewControl.NodeChecked + = new TreeViewPlusNodeCheckedEventHandler(TOCNodeCheckedServer)