简体   繁体   English

在某些时间调用时,TreeView Node前景色没有变化?

[英]TreeView Node forecolor not changing when called at certain times?

I have a treeview, trvActors. 我有一个树状视图,trvActors。

When I try to change the forecolor of a treenode by clicking on it, it does not seem to work, but the surrounding code works. 当我尝试通过单击更改树节点的前景色时,它似乎不起作用,但是周围的代码起作用了。

            ((Actor)_rightClickedNode.Tag).IsDefault = true;
            _rightClickedNode.ForeColor = Color.Red;

Weirdly enough, the isDefault value changes, but the node does not change color. 奇怪的是,isDefault值会更改,但节点不会更改颜色。 This is occurring on a toolstripmenuitem click, but the same thing is also occurring on a simple right click. 这是在工具条菜单单击上发生的,但是在简单的右键单击上也发生了相同的事情。

Here is the code for a right click on the private void trvActors_MouseClick event: 这是右键单击私有void trvActors_MouseClick事件的代码:

  trvActors.SelectedNode = trvActors.GetNodeAt(e.X, e.Y);

        if (trvActors.SelectedNode != null)
        {
            if (e.Button == MouseButtons.Right)
            {
                _rightClickedNode = trvActors.SelectedNode;

                ((Actor)_rightClickedNode.Tag).IsDefault = true;
                _rightClickedNode.ForeColor = Color.Red;

            }
        }

Same outcome. 结果一样。 The only time I seem to be able to change the forecolor is when I am initially creating the nodes. 我似乎唯一能够更改前景色的时间是在最初创建节点时。 Any ideas? 有任何想法吗?

what do you have FullRowSelect set to.. if it is true make it false also maybe you should put your code in the NodeMouseClick or BeforeSelect events ? 您将FullRowSelect设置为什么。.如果为true,则将其设置为false。也许您应该将代码放入NodeMouseClickBeforeSelect事件中?

Hope this helps you out, 希望这可以帮助你,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM