TreeView selectedNode始终为null [英] TreeView selectedNode is always null

查看:268
本文介绍了TreeView selectedNode始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我的treeView有问题。我通过LINQ-To-Entity语句从数据库构建我的树视图。



Hi!

I have a problem with my treeView. I build my treeview out of a database through LINQ-To-Entity statements.

treeView1.Nodes.Add(tree.InitializeTreeView_R3());





我的Treeview随后会填充,效果很好。现在我面临的问题是我无法获得节点的实际selectedNode文本,名称或标记。 SelectedNode始终为null!为什么?



http:// www.pic-upload.de/view-21565757/Unbenannt.png.html





我想写的将当前selectednode的文本放入文本框中。





我尝试了另一种让它工作的方法。我试图将实际的tooltiptext放到文本框中。但我不知道如何获取当前点击/选中节点的工具提示。

类似



< pre> myToolTip .GetToolTip(myControl)< / pre>



不起作用,因为它是treeview-control中的工具提示而不是我自己定义的工具提示(mytooltip) 。如何将我的treeview的实际工具文本放入文本框?





关于Adam



My Treeview is then populated and it works great. Now I´m facing the problem that i could not get the actual selectedNode text, name or tag of the node. SelectedNode is always null! Why?

http://www.pic-upload.de/view-21565757/Unbenannt.png.html


I want to write the text of the current selectednode into a textbox.


I tried an alternative way of get it to work. I tried to get the actual tooltiptext into a textbox. But I don´t know how to get the tooltiptext of the current clicked/selected node.
Something like

<pre>myToolTip.GetToolTip(myControl)</pre>

does not work, because it is a tooltip within the treeview-control and not a tooltip defined by myself(mytooltip). How can i get the actual tooltiptext of my treeview into a textbox?


regards Adam

推荐答案

尽管有Linq到实体的东西,它是一个标准的TreeeView,我知道SelectedNode属性有效 - 我自己用它。

所以问题是 - 你在哪里试着读它,你什么时候尝试,你到底是怎么做的?因为

Despite the Linq-to-entity stuff, it's a standard TreeeView, and I know the SelectedNode property works - I use it myself.
So the question is - where are you trying to read it, when are you trying, and exactly how are you doing it? Because
private void tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
    TreeView tv = sender as TreeView;
    if (tv != null)
        {
        Console.WriteLine(tree.SelectedNode);
        Console.WriteLine(tv.SelectedNode);
        Console.WriteLine(tv.SelectedNode.Text);



一切正常......同样如下:


all works fine...as does:

private void tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
    TreeView tv = sender as TreeView;
    if (tv != null)
        {
        TreeNode selected = e.Node;
        if (selected != null)
            {

这是我通常做的。


这篇关于TreeView selectedNode始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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