Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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());


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
Posted

1 solution

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
C#
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:
C#
private void tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    {
    TreeView tv = sender as TreeView;
    if (tv != null)
        {
        TreeNode selected = e.Node;
        if (selected != null)
            {
Which is what I normally do.
 
Share this answer
 
Comments
Member 8857897 8-Dec-13 11:14am    
Hey! Thank you very much! I used a wrong EventHandler. maybe I should go to sleep earlier :P
OriginalGriff 8-Dec-13 11:23am    
:laugh:
Easy to do, difficult to spot - because you always read what you meant to write, or I do... :sigh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900