VB编程如何将listbox中选中的多个选项添加至文本输入框?

2024-11-15 16:33:40
推荐回答(1个)
回答1:

假定文本框在Form1,列表框在Form2,则以下代码放在Form2:

Private Sub List1_Click()
Dim s As String, i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
If s <> "" Then s = s & ","
s = s & List1.List(i)
End If
Next
obj.Text = s
End Sub

以下代码放在Form1:

Private Sub Command1_Click() '第一个文本框后面的+按钮
Set Obj = Text1
Form2.Show
End Sub

Private Sub Command2_Click() '第二个文本框后面的+按钮
Set Obj = Text2
Form2.Show
End Sub

以下代码放在公共模块(Module)文件:

Public obj As Object