Hi,

I am working on tree View in taht i want to do two thinks i.e
1. add new node at run time
2. what data is stored in a database is shown in the tree view as parent node and
its child

for second i have do some coding it shows data as parent and child node but problem is it shows only one row record can any one help me correct the coding please

SqlConnection con = new SqlConnection("USER=userid;PASSWORD=password;SERVER=servername;DATABASE=database");
            string SQLQuery;
            SQLQuery = "select tablename,displayname from Tablename";
            DataSet ds=new DataSet();
            SqlDataAdapter da=new SqlDataAdapter(SQLQuery,con);
            da.Fill(ds);
            foreach ( DataRow Row in ds.Tables[0].Rows)
            {
                TreeNode Tnode = new TreeNode("ParentNode");
                treeView1.Nodes.Add(Tnode);
}

Thanks.....

Hey there,

First of all, in order to add a new PARENT node at runtime you should use this code:

TreeNode parent = new Node;
TreeView1.Nodes.Add(parent);

for a CHILD node:

TreeNode child = new Node;
TreeView1.SelectedNode.Nodes.Add(child);

Now, what has to do with the Data show, then you need to load all the data that you want in a collection(DataTable,List) and then create a recursive function in order to create the treeview structure on all depths.

Hope i helped. :)

i have database witht these column names id,nodename,nodelevel.
in this i have to add the value to the ultratree from database as parentnode and childnode. for example(state)is a parentnde ,its childnode as (tamilnadu)and(kerala).tamilnadu's childnode as(chennai) and( pondcherry) etc for this i want a ultratree to dispay it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.