Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            listView1.Items.Clear();
                            

                // write this code inside your treeview NodeMouseCLick event
                TreeNode tn = e.Node;
                //create a datatable with two columns
                  DataTable aTable = new DataTable();
                    aTable.Columns.Add("Headid", typeof(string));
                    aTable.Columns.Add("HeadName", typeof(string));


                //in this for each loop we will traverse through the clicked tree node 
                // and get all child nodes name and tag(value) and keep it in datarow 
                // of our datatable .        
                foreach (TreeNode t1 in tn.Nodes)
                {
                    DataRow dr;
                    dr = aTable.NewRow();
                    dr[0] = t1.Text;
                    dr[1] = t1.Tag.ToString();
                    aTable.Rows.Add(dr);
                }
                //finally we will make datatabe as the source of listview
                ListViewItem li;
                foreach (DataRow rr in aTable.Rows)
                {
                    li = listView1.Items.Add(rr[0].ToString());
                    li.SubItems.Add(rr[1].ToString());
                }

i have CTE table in sql name is tblhead.i am populated the treeview but i have to show after click parent node in treeview parents realted child show in listview.
how can i do??? listview.tag (tag showing null).plz tell me soluation.

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 23-Feb-12 4:15am

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