Here you go. :) If it helps, please mark it as a solution.
C# Version:
private void Main_Load(object sender, EventArgs e)
{
{
TV = new TreeView();
TV.Location = new Point(100, 104);
TV.Size = new Size(100, 50);
TV.Nodes.Add("Add Once");
TV.Nodes.Add("Add Twice");
CB = new ComboBox();
CB.Location = new Point(100, 160);
TV.AfterSelect += TV_Clicked;
Controls.Add(TV);
Controls.Add(CB);
}
}
private TreeView TV;
private ComboBox CB;
private void TV_Clicked(object sender, System.EventArgs e)
{
CB.Items.Add(TV.SelectedNode.Text);
}
VB.NET Version:
Private WithEvents TV As TreeView 'Declare the Treeview.
Private WithEvents CB As ComboBox ' Declare the Combobox - We do this instead of droping controls on the form.
Private Sub TV_Clicked(ByVal sender As Object, ByVal e As System.EventArgs)'Handler is added in Event Load.
CB.Items.Add(TV.SelectedNode.Text) 'Adds the Selected Node to the Combobox.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TV = New TreeView 'Create a new instance of the Treeview.
TV.Location = New Point(100, 104) 'Set the location of the treeview.
TV.Size = New Size(100, 50) 'Set the size of the treeview.
TV.Nodes.Add("And Once") 'Add a Node to the Treeview.
TV.Nodes.Add("Add Twice") 'Add another
CB = New ComboBox 'Create a new instance of the Combobox.
CB.Location = New Point(100, 160) 'Set the Combobox location.
AddHandler TV.AfterSelect, AddressOf TV_Clicked 'Add the AfterSelect Handler to add the items selected to the Combobox.
Controls.Add(TV) 'Now add the controls to the form
Controls.Add(CB) 'Same
End Sub