[英]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.