VB - 将多个项目从 ListBox 放入文本框
VB - Put multiple items from ListBox to textbox
我需要将多个 selected 项目从 ListBox 插入到 TextBox 中,如果我 deselect 某些项目,它将从文本框中删除。
示例:
- Name1 - selected
- 名字2
- 名字 3 - selected
结果:
文本框:姓名 1、姓名 3
我的代码:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim Name As String = ListBox1.SelectedItems.ToString
TextBox3.Text = Name + ", "
End Sub
但是当我 select 一个项目时,它会在文本框中插入这个“System.Windows.Forms.ListBox” 有人可以帮我吗?
ListBox.SelectedItems 是 collection。你有迭代扔它。
https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditems(v=vs.110).aspx
试试这个(c# 语法):
var names = string.Join(",",ListBox1.SelectedItems.Select(x=>x.ToString())
试试这个
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox3.Text = ""
For Each Name In ListBox1.SelectedItems
TextBox3.Text += Name + ", "
Next
End Sub
名称中可能包含文本属性
尝试 Name.text
或 Name.Caption
我不太记得了
我需要将多个 selected 项目从 ListBox 插入到 TextBox 中,如果我 deselect 某些项目,它将从文本框中删除。
示例:
- Name1 - selected
- 名字2
- 名字 3 - selected
结果:
文本框:姓名 1、姓名 3
我的代码:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim Name As String = ListBox1.SelectedItems.ToString
TextBox3.Text = Name + ", "
End Sub
但是当我 select 一个项目时,它会在文本框中插入这个“System.Windows.Forms.ListBox” 有人可以帮我吗?
ListBox.SelectedItems 是 collection。你有迭代扔它。 https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditems(v=vs.110).aspx
试试这个(c# 语法):
var names = string.Join(",",ListBox1.SelectedItems.Select(x=>x.ToString())
试试这个
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox3.Text = ""
For Each Name In ListBox1.SelectedItems
TextBox3.Text += Name + ", "
Next
End Sub
名称中可能包含文本属性
尝试 Name.text
或 Name.Caption
我不太记得了