Click here to Skip to main content
16,016,613 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //SqlConnection con = new SqlConnection("Data Source=AKS14;Initial Catalog=TreeviewSampleDb;Integrated Security=SSPI");
            //DataSet dataset = new DataSet();
            //con.Open();
            //dataset.Clear();
            //string strcon = "select * from tblHead";
            //SqlDataAdapter da = new SqlDataAdapter(strcon, con);
            //da.Fill(dataset);

            // 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();
            }
            //finally we will make datatabe as the source of listview
            listView1.datasource = aTable;

leftside treeview and right side listview in windows c#.after click parents node in treeview the child show in listview with his ids. how to do???
listview1.datasource is not working in windows.
Posted
Updated 23-Feb-12 1:07am
v3
Comments
Abhinav S 23-Feb-12 2:48am    
Code tags added.
Sergey Alexandrovich Kryukov 23-Feb-12 3:20am    
What is child view?
--SA
sadhana4 23-Feb-12 3:52am    
how to show child in listview after click parent node in treeview in windows in c#.
left side treeview and right side listview.than how to do??

1 solution

 
Share this answer
 

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