开发者

What event can I use when setting TreeView.SelectedNode = null?

When I set SelectedNode to null the tree updates correctly but BeforeSelect and AfterSelect do not fire.

Is there any way to tell when the selection has been cha开发者_如何学运维nged to null?

My first thought is to extend the control and add an event though I would have thought something like this would already be available.


I think your solution is good. However, I just discovered this control (keep an eye on SO's right column :)):

http://treeviewadv.sourceforge.net/

which supports what you're looking for, maybe has other goodies too...


It seems the only way I could do this was to create a new control and provide a new implementation for SelectedNode, even OnAfterSelect and OnBeforeSelect weren't getting called.

public new TreeNode SelectedNode {
    get { return base.SelectedNode; }
    set {
        // Remember, if `value' is not null this will be called in `base'.
        if (value == null) {
            TreeViewCancelEventArgs args
                = new TreeViewCancelEventArgs(value, false, TreeViewAction.Unknown);
            OnBeforeSelect(args);
            if (args.Cancel)
                return;
        }
        base.SelectedNode = value;
        // Remember, if `value' is not null this will be called in `base'.
        if (value == null) {
            OnAfterSelect(new TreeViewEventArgs(value, TreeViewAction.Unknown));
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜