因為我要與數據庫聯系起來,所以必須後台編寫:
tree view 後台編寫'tree 綁定
End Sub

tree view 後台編寫 '點擊tree編輯
End Sub

.Parent获得父结点,爷爷就是  
  ((TreeNode)((TreeNode)this.TreeView1.GetNodeFromIndex(this.TreeView1.SelectedNodeIndex).Parent).Parent).NodeData

判斷點擊的節點層:
Me.TreeView1.SelectedNode.Depth


private   void   NodeLostManagement(   string   errorID   )  
  {  
  //   Show   Message  
  this.ShowMessage(this.GetMessage(errorID));  
   
  //   Get   New   Tree   Info  
  DataTable   dtTree   =   new   DmsDB.TreeOperationDB().GetTreeData();  
   
  //   Old   Tree   SelectedIndex  
  string   oldTreePath   =   this.tvDocDir.SelectedNodeIndex;  
   
  //   New   Tree   SelectedIndex  
  string   newTreePath   =   string.Empty;  
   
  //   Check   Old   Node   (first   Check   Root   Node)  
  TreeNode   currentNode   =   this.tvDocDir.Nodes[0];  
   
  //   Split   OldSelectedIndex  
  string   []   oldNodeIndex   =   oldTreePath.Split('.');  
   
  for(int   i   =   0;i   <oldNodeIndex.Length   ;i++)  
  {  
  //   if   node   id   exists   in   the   new   tree    
  //   we   add   it   into   new   tree   selectedIndex  
  if(dtTree.Select("NodeId   ="   +   currentNode.ID).Length   >   0)  
  {  
  if(   i   ==   0   )  
  {  
  //   Move   Check   Node   into   next   node   (   Old   Tree   )  
  currentNode   =   currentNode.Nodes[int.Parse(oldNodeIndex[i+1])];  
  //   Root   Node    
  newTreePath   =   oldNodeIndex[i];  
  }  
  else  
  {  
  //   Move   Check   Node   into   next   node   (   Old   Tree   )  
  currentNode   =   currentNode.Nodes[int.Parse(oldNodeIndex[i+1])];  
  //   Sub   Node  
  newTreePath   =   newTreePath   +   "."   +   oldNodeIndex[i];  
  }  
  }  
  }  
   
  //   Rebuild   Tree  
  this.rebuildTree(newTreePath);  
   
  //   Refresh   the   screen  
  tvDocDir_SelectedIndexChange(   new   object()   ,   new   Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs("0","0"));  
  }

Private   Sub   TreeView1_AfterCheck(ByVal   sender   As   Object,   ByVal   e   As   System.Windows.Forms.TreeViewEventArgs)   Handles   TreeView1.AfterCheck  
                  Try  
                          TreeView1.BeginUpdate()  
                          If   e.Action   <>   Windows.Forms.TreeViewAction.Unknown   Then  
                                  If   e.Node.Nodes.Count   >   0   Then  
                                          '   Calls   the   CheckAllChildNodes   method,   passing   in   the   current    
                                          '   Checked   value   of   the   TreeNode   whose   checked   state   changed.    
                                          Me.CheckAllChildNodes(e.Node,   e.Node.Checked)  
                                  End   If  
                                  If   Not   e.Node.Parent   Is   Nothing   Then  
                                          Me.CheckParentNodes(e.Node.Parent)  
                                  End   If  
                          End   If  
                          TreeView1.EndUpdate()  
                  Catch   ex   As   Exception  
                          Windows.Forms.MessageBox.Show(ex.Message)  
                  End   Try  
          End   Sub  
   
          Private   Sub   CheckAllChildNodes(ByVal   treeNode   As   Windows.Forms.TreeNode,   ByVal   nodeChecked   As   Boolean)  
                  Dim   node   As   Windows.Forms.TreeNode  
                  For   Each   node   In   treeNode.Nodes  
                          node.Checked   =   nodeChecked  
                          If   node.Nodes.Count   >   0   Then  
                                  '   If   the   current   node   has   child   nodes,   call   the   CheckAllChildsNodes   method   recursively.  
                                  Me.CheckAllChildNodes(node,   nodeChecked)  
                          End   If  
                  Next   node  
          End   Sub  
   
          Private   Sub   CheckParentNodes(ByVal   treeNode   As   Windows.Forms.TreeNode)  
                  Dim   node   As   Windows.Forms.TreeNode  
                  Dim   flag   As   Boolean   =   False  
                  For   Each   node   In   treeNode.Nodes  
                          If   node.Checked   Then  
                                  flag   =   True  
                          End   If  
                  Next  
                  treeNode.Checked   =   flag  
                  If   Not   treeNode.Parent   Is   Nothing   Then  
                          Me.CheckParentNodes(treeNode.Parent)  
                  End   If  
          End   Sub  
   
  你看一下这个代码。需要把treeview前面打checkbox打开。
http://topic.csdn.net/t/20010912/10/283301.html

相关文章:

  • 2022-12-23
  • 2021-07-18
  • 2022-02-13
  • 2022-12-23
  • 2021-10-17
  • 2021-08-24
  • 2021-07-12
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2022-01-25
  • 2021-12-15
  • 2021-07-27
  • 2022-12-23
  • 2021-09-25
相关资源
相似解决方案