Mark Evans
Mark Evans

Reputation: 5

Display selected node of treeview control in textbox in vb.net

i am beginner to .net and i want to put selected node string to a textbox. May be it is not possible to do with treeview control because it has no use in application.

ps I tried to insert choices in listcheckbox control on a button click, may be this thing is also not possible.

Do you have another way of doing this

Upvotes: 0

Views: 12494

Answers (2)

xpda
xpda

Reputation: 15813

Use the BeforeSelect or AfterSelect event to put a selected node's text into a textbox.

textbox1.text = e.node.text

Use checkedlistbox1.items.add() to add an item to a checkedlistbox.

Upvotes: 0

xfx
xfx

Reputation: 1358

The TreeView control has an event called AfterSelect. You can use this event to detect when an item has been selected.

Here's a sample code:

Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect
    extBox1.Text = e.Node.Text
End Sub

Of course, you will need to change TreeView1 and TextBox1 for the actual names of your treeview and textbox controls.


To add items to a CheckedListBox when a button is clicked, you would use a code similar to this one:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text <> "" Then CheckedListBox1.Items.Add(TextBox1.Text)
End Sub

This code will add a new item to CheckedListBox1, using the text from the TextBox1 control as input, when Button1 is clicked.

Upvotes: 2

Related Questions