我有这样的代码:
private void treeview1_AfterCheck(object sender, TreeViewEventArgs e)
{
// I tried this, but not helped
// treeview1.BeginUpdate();
if (e.Node.Level == 0)
{
foreach (TreeNode item in e.Node.Nodes)
{
item.Checked = e.Node.Checked;
}
}
// this is a method that executes slow enough,
// that I can click multiple times before it ends
RefreshListOfSelectedItems();
// I tried this, but not helped
// treeview1.EndUpdate();
}
基本上 - 这应该将“Checked”状态复制到子节点,但问题是当我单击复选框足够快时 - 一切都搞砸了,因为(我认为)我的事件处理程序执行得比我点击的要慢。 / p>
答案 0 :(得分:0)
void checkChildren(TreeNode node)
{
foreach (TreeNode tn in node.Nodes)
tn.Checked = true;
}
//After check event for treeView
void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Node.Checked) checkChildren(e.Node);
}
我检查了这个,正在为孩子和他们所有的孩子工作。