禁用或变灰在树节点编辑器节点 [英] Disable or grey out a node in the TreeNode Editor

查看:493
本文介绍了禁用或变灰在树节点编辑器节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何禁用特定节点,以便用户无法选择它。隐藏它对于用户也是有效的。

How do I disable a specific node so the user can not select it. Hiding it for the user is also valid.

我试过Visible属性,但隐藏整个树(所有节点)。我只使用Visual Studio 2005树节点编辑器要几个节点禁用/隐藏。

I tried the Visible property but that hides the entire tree (all nodes). I only want a few of the nodes disabled/hidden.

C#。

推荐答案

树节点本身不具有任何已启用属性,所以您需要找到追踪国家的一些手段。要做到这一点的方法之一是创建一个继承树节点一个新的类,并且拥有一个已启用属性。另一种方法是保持禁用树节点的列表。

The TreeNode itself does not have any Enabled property, so you will need to find some means of tracking that state. One way to do this is to create a new class that inherits TreeNode and that features an Enabled property. Another way is to maintain a list of disabled tree nodes.

一旦做到这一点,您可以使用的 前景色 财产树节点有它使用 <$ 。C $ C> SystemColors.GrayText 值)

Once that is done, you can use the ForeColor property of the TreeNode to have it appear grayed out (for instance using the SystemColors.GrayText value).

最后,你可以使用的 BeforeSelect 事件,以评估它是否为确定用户选择特定的节点,并使用事件参数的取消属性在该事件中,以防止选择它,如果该节点已禁用:

Finally you can use the BeforeSelect event to evaluate whether it's OK for the user to select a particular node, and use the Cancel property of the event args in that event to prevent selecting it if that node is disabled:

private void TreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
    e.Cancel = !NodeIsEnabled(e.Node);
}

这篇关于禁用或变灰在树节点编辑器节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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