简体   繁体   English

如何在C#.net(2010)Windows窗体应用程序中获取TreeView控件中的所有复选框值?

[英]how to get the All the Checkbox values in TreeView control in C#.net(2010) Windows Forms Application?

I have one Tree View Control with check boxes in my Windows Forms Application.Whenever user selected multiple Checkboxes, then i want to display the all the selected checkboxes node's path.How i do it? 我的Windows窗体应用程序中有一个带有复选框的树视图控件。每当用户选择多个复选框时,我想显示所有选中的复选框节点的路径。如何操作?

And also How to automatically select or deselect the all child nodes whenever its parent Node is selected or deselected? 以及如何在选择或取消选择其父节点时自动选择或取消选择所有子节点?

protected string getCheckedNodes(TreeNodeCollection tnc)
    {
        StringBuilder sb = new StringBuilder();

        foreach (TreeNode tn in tnc)
        {
            if (tn.Checked)
            {
                string res = tn.FullPath;
                if (res.Length > 0)
                    sb.AppendLine(res);
            }
            string childRes = getCheckedNodes(tn.Nodes);
            if (childRes.Length > 0)
                sb.AppendLine(childRes);
        }

        return sb.ToString();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show(getCheckedNodes(treeView1.Nodes));
    }

I've made it output via string but you can obviously do anything you like with it like add it to a collection etc. 我已经通过字符串输出了它,但你显然可以做任何你喜欢的事情,比如将它添加到集合等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改我的treeView图标+, - 像c#.net win窗体中的Windows资源管理器树视图 - How to change my treeView icons insted of +,- like a windows explorer treeview in c#.net win forms C#.NET-如何从现有的Windows窗体控件继承 - C#.NET - How to inherit from an existing windows forms control 如何将文本框值传递给Windows窗体应用程序的c#.net中的方法 - how to pass textbox values to a method in c#.net for windows forms application 如何在C#.net Windows应用程序中获取系统内存? - How to get System Memory in C#.net windows application? 如何使用 USB 电缆 C#.net 将文件从 Windows 表格申请传输到 Xamarin Forms - How to transfer the file from Windows Form Application to Xamarin Forms using USB cable C#.net 扩展C#.net上的复选框控件 - Extend checkbox control on C#.net 如何在c#.net窗口中获取存储过程的所有代码并在c#.net窗口中创建存储过程的textFile - how to get all code of stored procedure in c#.net window and create textFile of storedprocedure in C#.net window Application 在c#.net中使用Windows应用程序获取列表中的复选框列表值 - Get check box list values in List using windows application in c#.net 如何重新调整图像C#.net Windows窗体的大小 - How To Re-size An Image C#.net Windows Forms Windows应用程序(C#.Net)-保留文本框值 - Windows Application (C#.Net)- Retain TextBox Values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM