Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,everyone,I'm new in using treeview control in VB.NET ,so I faced some problems about it...What I want is like below:
When I click one of the treenodes,it will call some event or others such as one messagebox displayed.
But I don't know how to do this.I found that there was no "click" event about treenodes...
Plz help me or give me some suggestion!Thanks a lot!
Posted

No, the Click event is part of the TreeView.
You get the event, decide which node it is and off you go...
 
Share this answer
 
Comments
sanyexian 10-Jul-10 8:19am    
It is working now!Thank you!
You can try subscribing to AfterSelect of NodeMouseClick events:

C#
// Handle the After_Select event.
    private void TreeView1_AfterSelect(System.Object sender,
        System.Windows.Forms.TreeViewEventArgs e)
    {
        // Vary the response depending on which TreeViewAction
        // triggered the event.
        switch((e.Action))
        {
            case TreeViewAction.ByKeyboard:
                MessageBox.Show("You like the keyboard!");
                break;
            case TreeViewAction.ByMouse:
                MessageBox.Show("You like the mouse!");
                break;
        }
    }

or
C#
void treeView1_NodeMouseClick(object sender,
    TreeNodeMouseClickEventArgs e)
{
    textBox1.Text = e.Node.Text;
}
 
Share this answer
 
Comments
sanyexian 10-Jul-10 10:52am    
Reason for my vote of 5
good example!
Hi,Griff!Thank you for your answer,I think that I must learn more about the treeview control...Thanks a lot! I will try like what you said!
 
Share this answer
 

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