日期:2014-05-18 浏览次数:20684 次
public static void GetCheckedNode(TreeNodeCollection tnc) { foreach(TreeNode node in tnc) { if(node.Checked) { MessageBox.Show(node.Text); } GetCheckedNode(node.Nodes); } }
------解决方案--------------------
private void button1_Click(object sender, EventArgs e) { List<TreeNode> t = getchecknode(this.treeView1.Nodes); } private List<TreeNode> getchecknode(TreeNodeCollection nodes) { List<TreeNode> getnodes = new List<TreeNode>(); foreach (TreeNode td in nodes) { if (td.Checked) getnodes.Add(td); if(td.Nodes.Count!=0) { getnodes.AddRange(getchecknode(td.Nodes)); } } return getnodes; }