Click here to Skip to main content
14,977,402 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am doing a user Management in Desk top based project using tree view
My tree view Name mytreeview
myTreeView.CheckBoxes = true;
this.Controls.Add(myTreeView);
myTreeView.ExpandAll();

Now i want to save and Update check box checked data in to database sqlserver2005.
Table Name
ParentTable(ParentID,ParentName)
ChildTable(ChildID,ParentID,ChildName,IsActive)

void fill_Tree2(TreeView treeView1)
       {

           DataSet PrSet = DB_Manager.SelectDataSet("Select * from service", "sub_header");

           treeView1.Nodes.Clear();
           try
           {
               foreach (DataRow dr in PrSet.Tables["sub_header"].Rows)
               {

                   TreeNode tnParent = new TreeNode();

                   tnParent.Text = dr["ParentName"].ToString();

                   tnParent.Tag = dr["ParentID"].ToString();

                   tnParent.Expand();

                   treeView1.Nodes.Add(tnParent);

          FillChild(tnParent, Convert.ToInt32(tnParent.Tag),treeView1);

               }
           }catch(Exception)
           {
           }



       }
       public void FillChild(TreeNode parent, int ParentId,TreeView treeview1)
       {
DataSet ds = DB_Manager.SelectDataSet("Select * from ServiceSetting where ParentID =" + ParentId + " ", "sub_header");

           foreach (DataRow dr in ds.Tables["sub_header"].Rows)
           {

               TreeNode child = new TreeNode();
               child.Text = dr["ChildName"].ToString().Trim();

               child.Tag = dr["ChildId"].ToString().Trim();
               parent.Nodes.Add(child);
               if (Convert.ToInt32(dr["IsActive"]) == 1)
               {
                   child.Checked = true;
               }

           }

       }

I can not catch the node id value.
I am doing
After select check event

TreeNode node=new TreeNode();
   int  NodeID = Convert.ToInt32(node.Tag);

but it can't work.
How can i solve this problem.I want to know how tree view check box checked data save and update into database.
I am a novice developer,Any Help thanks in advance.
Masud
Posted
Updated 15-Jun-10 22:14pm
v2

1 solution

As fer as I got,this function in my own analysis.I think it should be great if i delivery this answer.

// Call the procedure using the TreeView.
            private void CallRecursive(TreeView treeView)
            {
               // Print each node recursively.
               TreeNodeCollection nodes = treeView.Nodes;
               foreach (TreeNode n in nodes)
               {
                   printRecursive(n);
               }
            }


public void printRecursive(TreeNode myTreeNode)
        {
            int active = 0;

            foreach (TreeNode node in myTreeNode.Nodes)
            {

                if (node.Checked == true)
                {
                    active = 1;
                }
            }
         }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900