-1

我有这样的代码:

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();
 }

基本上 - 这应该将“已检查”状态复制到子节点,但问题是当我足够快地点击复选框时 - 一切都搞砸了,因为(我认为)我的事件处理程序执行得比我可以点击的慢。

4

1 回答 1

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);
    }

我检查了这个,正在为孩子和他们所有的孩子工作。

于 2013-09-25T20:42:12.980 回答