获取 listBox.selectedItems 的文本?
Get text of listBox.selectedItems?
我有一个显示通讯组成员的列表框。我有多个简单 selection 到 select 多个成员的列表框设置。我正在尝试循环以获取 selected 项目(索引)的文本。这是我的代码,适用于第一项。在第二个项目上,它崩溃并显示 "Index was outside the bounds of the array." 我将带走这些成员并将他们放入会议请求的收件人:字段中。所以我需要这样格式化:member1;member2。我只是使用 MsgBox 来测试我得到的结果。但我猜我需要添加到数组中。请帮忙!
For i = 0 To (myListBox.Items.Count - 1)
If myListBox.GetSelected(i) Then
MsgBox(myListBox.SelectedItems(i))
End If
Next
重新阅读问题,我认为您想将其存储为字符串。这应该可以满足您的需求:
Documentation on ListBox.Selected()
Dim MailStr as String
MailStr = ""
If myListBox.SelectedItems.Count = 0 Then
MsgBox "No User Selected"
Exit Sub
End If
For i = 0 to (myListBox.Items.Count - 1)
If myListBox.Selected(i) Then
MailStr = MailStr & myListBox.Items.Item(i) & "; "
End If
Next i
您也可以试试:
Dim assets As String
assets = ""
For Each item In assetListBox.SelectedItems
If assets = Nothing Then
assets = item
'Outputs 1 item "Member1"
MsgBox(assets)
Else
assets = assets & "; " & item
'Outputs 2 items in format "member1; member2"
MsgBox(assets)
End If
Next
这就是我想要的方式。
Dim assets As String
assets = ""
For Each item In assetListBox.SelectedItems
If assets = Nothing Then
assets = item
'Outputs 1 item "Member1"
MsgBox(assets)
Else
assets = assets & "; " & item
'Outputs 2 items in format "member1; member2"
MsgBox(assets)
End If
Next
我有一个显示通讯组成员的列表框。我有多个简单 selection 到 select 多个成员的列表框设置。我正在尝试循环以获取 selected 项目(索引)的文本。这是我的代码,适用于第一项。在第二个项目上,它崩溃并显示 "Index was outside the bounds of the array." 我将带走这些成员并将他们放入会议请求的收件人:字段中。所以我需要这样格式化:member1;member2。我只是使用 MsgBox 来测试我得到的结果。但我猜我需要添加到数组中。请帮忙!
For i = 0 To (myListBox.Items.Count - 1)
If myListBox.GetSelected(i) Then
MsgBox(myListBox.SelectedItems(i))
End If
Next
重新阅读问题,我认为您想将其存储为字符串。这应该可以满足您的需求:
Documentation on ListBox.Selected()
Dim MailStr as String
MailStr = ""
If myListBox.SelectedItems.Count = 0 Then
MsgBox "No User Selected"
Exit Sub
End If
For i = 0 to (myListBox.Items.Count - 1)
If myListBox.Selected(i) Then
MailStr = MailStr & myListBox.Items.Item(i) & "; "
End If
Next i
您也可以试试:
Dim assets As String
assets = ""
For Each item In assetListBox.SelectedItems
If assets = Nothing Then
assets = item
'Outputs 1 item "Member1"
MsgBox(assets)
Else
assets = assets & "; " & item
'Outputs 2 items in format "member1; member2"
MsgBox(assets)
End If
Next
这就是我想要的方式。
Dim assets As String
assets = ""
For Each item In assetListBox.SelectedItems
If assets = Nothing Then
assets = item
'Outputs 1 item "Member1"
MsgBox(assets)
Else
assets = assets & "; " & item
'Outputs 2 items in format "member1; member2"
MsgBox(assets)
End If
Next