vb.net 在vb.net中的文本框中显示树视图控件的选定节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14484743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display selected node of treeview control in textbox in vb.net
提问by Mark Evans
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.
我是 .net 的初学者,我想将选定的节点字符串放入文本框。可能无法使用树视图控件,因为它在应用程序中没有用。
ps I tried to insert choices in listcheckbox control on a button click, may be this thing is also not possible.
ps 我试图在单击按钮时在 listcheckbox 控件中插入选项,可能这件事也不可能。
Do you have another way of doing this
你有另一种方法吗
回答by xfx
The TreeView control has an event called AfterSelect.
You can use this event to detect when an item has been selected.
TreeView 控件有一个名为 的事件AfterSelect。您可以使用此事件来检测何时选择了项目。
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 TreeView1and TextBox1for the actual names of your treeview and textbox controls.
当然,你需要改变TreeView1,并TextBox1为您的TreeView和TextBox控件的实际名称。
To add items to a CheckedListBoxwhen a button is clicked, you would use a code similar to this one:
要CheckedListBox在单击按钮时向 a 添加项目,您可以使用类似于以下代码的代码:
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 TextBox1control as input, when Button1is clicked.
此代码将添加一个新项目到CheckedListBox1,使用来自TextBox1控件的文本作为输入,当Button1被单击时。
回答by xpda
Use the BeforeSelect or AfterSelect event to put a selected node's text into a textbox.
使用 BeforeSelect 或 AfterSelect 事件将选定节点的文本放入文本框中。
textbox1.text = e.node.text
Use checkedlistbox1.items.add()to add an item to a checkedlistbox.
使用checkedlistbox1.items.add()将项目添加到checkedlistbox。

