C#树视图和列表视图 [英] C# treeview and listview

查看:101
本文介绍了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> http://www.progtalk.com/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: http://www.progtalk.com/viewarticle.aspx?articleid=16[^]


这篇关于C#树视图和列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆