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()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)