Hi all
the treeview i am creating here works very well but i tried so many ways to add tag to the child nodes but i could not... can any one tell me how to add tag to the nodes... that are created from the database...

I could add tag to rootNode but cannot add to child nodes...

public void FillTree()
            SqlCeConnection Connect = new SqlCeConnection("Data Source = data.sdf");


            DataTable dtTree = new DataTable();
            string sql = "SELECT * FROM Assembly";
            SqlCeDataAdapter Adapt = new SqlCeDataAdapter(sql, Connect);

            TreeNode rootNode = treeView1.Nodes.Add("Root");
            rootNode.Tag = "RootDB";

            CreateTreeView(rootNode.Nodes, 0, dtTree);


        // create tree 
        public void CreateTreeView(TreeNodeCollection parentNode, int parentID, DataTable mytab)
            foreach (DataRow dta in mytab.Rows)
                if (Convert.ToInt32(dta["ParentId"]) == parentID)

                    String key = dta["Id"].ToString();
                    String text = dta["Name"].ToString();
                    TreeNodeCollection newParentNode = parentNode.Add(key, text).Nodes;
                    CreateTreeView(newParentNode, Convert.ToInt32(dta["Id"]), mytab);


No it is not the way i have done the coding .... does not work for me... is there any other way... i have constructed the tree just need to add tag to it.. that is all....

Thanks for the reply

Surely all you need to do is newParentNode.Tag = <some value>; maybe newParentNode.Tag = dta; Ignore this. See next post.

Edited 5 Years Ago by nick.crane: n/a

You need to modify your CreateTreeView to take the node not the collection.

To add a new node use

TreeNode newParentNode = parentNode.Nodes.Add(key, text);

Then you can use newParentNode.Tag = <some value>;

Edited 5 Years Ago by nick.crane: n/a

This question has already been answered. Start a new discussion instead.