Friday, 1 February 2013

TreeView Node Select and Disselect

  private void btnUncheckAll_Click(object sender, EventArgs e)
        {
            try
            {
            string status = btnUncheckAll.Text.Trim();
            if (status == "Uncheck All")
            {
                ResetPrevileges();
                trvPrevileges.CollapseAll();
                btnUncheckAll.Text = "Check All";
            }
            else
            {
                ResetPrevileges();
               
                foreach (TreeNode ptn in trvPrevileges.Nodes)
                {
                    ptn.Checked = true;
                  
                }
                trvPrevileges.ExpandAll();
                btnUncheckAll.Text = "Uncheck All";
            }
            }
            catch (Exception ex)
            {

            }
        }

  private void ResetPrevileges()
        {
            foreach (TreeNode ptn in trvPrevileges.Nodes)
            {
                ptn.Checked = false;
                foreach (TreeNode subnodes in ptn.Nodes)
                {
                    subnodes.Checked = false;
                }
            }
        }

Deesign

No comments:

Post a Comment