在选中父节点时,不要取消选中子节点 [英] not uncheck the child node while parent node is checked

查看:103
本文介绍了在选中父节点时,不要取消选中子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次在我的窗口应用程序中使用树视图控件,我的问题是,如果检查了树视图的父节点,那么如果用户想要取消选中子节点,则用户将无法取消对其进行拆分通过强制将子节点取消选中子节点的父节点.

在此先感谢

Rathi

hi frind i have a tree view control using first time in my window application, my problem is that if the parent node the the tree view is checked then the user can not able to unckeck the the childe node if he want to uncheck the child node by compulsion uncheck the parent node of the child node first.

Thanks in advance

Rathi

推荐答案

假设您使用的是Winforms,请处理TreeView的BeforeCheck事件:
Assuming you are using Winforms, handle the BeforeCheck event for the TreeView:
private void myTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e)
    {
    if (e.Node.Parent != null && e.Node.Parent.Checked && e.Node.Checked)
        {
        e.Cancel = true;
        }
    }

除非直接父级也未选中,否则这将禁止取消选中节点.
如果这不是您要实现的目标,则您的问题尚不清楚,因此请更清楚地说明您要实现的目标.

This forbids unchecking nodes unless the immediate parent is also unchecked.
If this is not what you are trying to achieve, it is not clear from your question, so please explain what you are trying to achieve more clearly.


这篇关于在选中父节点时,不要取消选中子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆