TreeNode.ValuePath错误 [英] TreeNode.ValuePath Error

查看:135
本文介绍了TreeNode.ValuePath错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在使用TreeView。当我更新我的一个节点时,我重新填充TreeView。


我想扩展节点并选择我刚刚更新的节点。


我的代码在我的TreeView的一部分上工作,并且在另一部分上使用相同的代码不起作用。


基本上,我得到一个空引用异常尝试选择节点。 


当我在获得异常后检查路径时,我注意到路径的第一部分缺失(例如,我的路径应该是1/2 / 3,但它只显示2/3)。在内部ValuePath属性上,它确实显示了已完成的预期路径。


如果我使用debug并监视变量,或者在继续之前查看变量的ValuePath,则值是正确的并且代码运行完美。


关于这个的任何想法?听起来像是TreeNode类中的一个错误?

解决方案

你好


Hello,

I am using a TreeView. When I update one of my nodes, I repopulate the TreeView.

I want to Expand the nodes and select the node that I just updated.

I have code that is working for this on one part of my TreeView, and that is not working on the other part with the same code.

Basically, I get a null reference exception when I try to select the node. 

When I check the path after getting the exception, I notice that the first part of my path is missing (Ex. My path should be 1/2/3, but it is only showing 2/3). On the internal ValuePath property, it does show the completed expected path.

If I use debug and have a watch for the variable, or look at the variable's ValuePath before continue, the value is correct and the code runs perfect.

Any ideas on this one? Sounds like a bug in the TreeNode class to me?

解决方案

Hi Jeremy Vaughn,

Thank you for posting here.

For your question, I could not reproduce your exception, could you provide a simple code for us to test?

How do you update the nodes?

I use the way below to update, there is no error for me.

     private void _0326_Load(object sender, EventArgs e)
        {
            TreeNode treeNode = new TreeNode("Windows");
            treeView1.Nodes.Add(treeNode);
            TreeNode node = new TreeNode("1");
            TreeNode node1 = new TreeNode("2");
            TreeNode[] array = new TreeNode[] { node, node1 };
            treeNode = new TreeNode("Linux", array);
            treeView1.Nodes.Add(treeNode);
            TreeNode node2 = new TreeNode("C#");
            TreeNode node3 = new TreeNode("VB.NET");
            TreeNode[] array1 = new TreeNode[] { node2, node3 };
            treeNode = new TreeNode("Do", array1);
            treeView1.Nodes.Add(treeNode);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            treeView1.Nodes[1].Text = "upgrade";
        }


Best Regards,

Wendy


这篇关于TreeNode.ValuePath错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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