在树状视图中禁用节点 [英] disable a node in tree view

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

问题描述

嗨亲爱的
我设计了一个显示我的信息的树状视图,
我想当名称node ="sample"时自动禁用,
我该怎么办?
衷心感谢您的

hi dear''s
i design a treeview which show my information,
i want when name node="sample" it''s automaticaly disabled,
how i can??
sincerely yours

推荐答案

AFAIK,您无法自动执行-没有可以处理的添加节点"事件,因此您必须手动检查每个您添加节点的时间.
另一个问题是TreeNodes没有Enabled属性,因此如果不做一些稍微复杂的处理就不能禁用它.

您想达到什么目的,您认为这会有所帮助?可能有更好的解决方案.
AFAIK, you can''t do it automatically - there is no "Node added" event you can handle, so you would have to check manually every time you add a node.
The other problem is that TreeNodes doen''t have an Enabled property, so you can''t disable it without doing some slightly complicated processing.

What are you trying to achieve, that you think this would help? There may be a better solution.


尽管没有"enabled"属性,但可以通过将节点变灰并避免任何人单击它来模拟它.也许这可以工作:
Although there is no "enabled" property, you can simulate it by graying out the node and avoiding that anyone can click on it. Maybe this could work:
private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
  if (Color.Gray == e.Node.ForeColor)
    e.Cancel = true;
}

private void Form1_Load(object sender, EventArgs e)
{
  foreach (TreeNode node in treeView1.Nodes)
    if (node.Text == "sample")
      node.ForeColor = Color.Gray;
}


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

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