Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanna put check box inside treeview in this code
i mean i wanna show check boxes when treeview has loaded :( i do not know how
Thanks


C#
public SqlConnection con = new SqlConnection();
        protected void Page_Load(object sender, EventArgs e)
        {
            Load_tree();
        }

        protected DataSet PDataset(string select_statement)
        {
            Connect();
            con.Open();
            SqlDataAdapter ad = new SqlDataAdapter(select_statement, con);
            DataSet ds = new DataSet();
            ad.Fill(ds);
            con.Close();
            return ds;
        }

        public void Connect()
        {
            con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["cnstring"].ConnectionString);
        }

        public void Load_tree()
        {
            DataSet PrSet = PDataset("SELECT * FROM Location where ID>1");
            TreeView1.Nodes.Clear();
            foreach (DataRow dr in PrSet.Tables[0].Rows)
            {
                if ((int)dr["ParentID"] == 1)
                {
                    TreeNode tnParent = new TreeNode();
                    tnParent.Text = dr["Title"].ToString();
                    string value = dr["ID"].ToString();
                    tnParent.Expand();
                    TreeView1.Nodes.Add(tnParent);
                    FillChild(tnParent, value);
                }
            }
        }

        public int FillChild(TreeNode parent, string IID)
        {
            DataSet ds = PDataset("SELECT * FROM Location WHERE ParentID =" + IID);
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    TreeNode child = new TreeNode();
                    child.Text = dr["Title"].ToString().Trim();
                    string temp = dr["ID"].ToString();
                    child.Collapse();
                    parent.ChildNodes.Add(child);
                    FillChild(child, temp);
                }
                return 0;
            }
            else
            {
                return 0;
            }
        }
Posted
Updated 11-Aug-12 19:19pm
v2

1 solution

 
Share this answer
 
Comments
Mina Mansouri 18-Aug-12 3:43am    
it works but it doesn't show check boxes!!! i enabled SHOWCHECKBOXES but still has a problem help me pleassssssssssssssss :(((((

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