C#树视图和列表视图

编程入门 行业动态 更新时间:2024-10-07 10:21:02
本文介绍了C#树视图和列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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[^]

更多推荐

C#树视图和列表视图

本文发布于:2023-11-30 06:42:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!