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;
在Windows c#中单击左侧的树视图和右侧的列表视图.在树视图中单击父节点"后,子级将以其ID在列表视图中显示.怎么办??? listview1.datasource在Windows中不起作用. articleid = 16> www.progtalk/viewarticle.aspx?articleid=16 [ ^ ]
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.
解决方案 Nice reference available at: www.progtalk/viewarticle.aspx?articleid=16[^]