Home>
class treeviewchecked
{
  bool isfirst=true;
  public treeviewchecked (treeview treeview)
  {
   treeview.aftercheck +=new treevieweventhandler (treeview_aftercheck);
   treeview.afterselect +=new treevieweventhandler (treeview_afterselect);
  }
  ///<summary>
  ///click on the text,Checkbox checked
  ///</summary>
  ///<param name="sender"></param>
  ///<param name="e"></param>
  void treeview_afterselect (object sender, treevieweventargs e)
  {
   if (e.node.checked)
    e.node.checked=false;
   else
    e.node.checked=true;
   if (isfirst)
   {
    isfirst=false;
    e.node.treeview.nodes [0] .checked=false;
   }
  }
  ///<summary>
  ///select the child node,Check the parent node,Select the parent node,Check child nodes
  ///</summary>
  ///<param name="sender"></param>
  ///<param name="e"></param>
  void treeview_aftercheck (object sender, treevieweventargs e)
  {
   checktreenode (e.node);
  }
  ///<summary>
  ///select the child node,Check the parent node,Select the parent node,Check child nodes
  ///</summary>
  ///<param name="node"></param>
  private void checktreenode (treenode node)
  {
   node.treeview.aftercheck-= new treevieweventhandler (treeview_aftercheck);
   //If not equal to null, it means that the child node is selected
   if (node.parent!=null)
   {
    treenode parent=node.parent as treenode;
    //If the node is selected
    if (node.checked)
    {
     //determine if its parent node is selected,Select it if it is not already selected
     if (parent.checked == false)
     {
      parent.checked=true;
     }
    }
    else
    {
     bool ischecked=false;
     foreach (treenode child in parent.nodes)
     {
      if (child.checked)
      {
       ischecked=true;
       break;
      }
     }
     if (ischecked)
      parent.checked=true;
     else
      parent.checked=false;
    }
   } //If equal to null, it means that the root node is selected
   else
   {
    foreach (treenode child in node.nodes)
    {
     child.checked=node.checked;
    }
   }
   node.treeview.aftercheck +=new treevieweventhandler (treeview_aftercheck);
  }
}
c
  • Previous JQuery to achieve picture carousel effect
  • Next jquery image carousel special effects code sharing