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