2013-10-20 54 views
0

我有一個列表框...我的列表框有多個項目..如果我選擇多個項目我想顯示多個項目同時在消息框..我的代碼是這樣的:選定的列表框值顯示togethar

cnt = LSTlocations.SelectedItems.Count 
Dim list As New List(Of Integer) 
Dim locid As Integer 
If cnt > 0 Then 
     For i = 0 To cnt - 1 
      Dim locationanme As String = LSTlocations.SelectedItems(i).ToString 
      locid = RecordID("Locid", "Location_tbl", "LocName", locationanme) 
      list.Add(locid) 
     Next 

     For Each num In list 
      MessageBox.Show("LocID:" & num) 

     Next 

現在每次我在消息框中獲得每個值..我想同時獲得所有的價值..我可以做到這一點?

回答

1

您可以使用String.Join()方法而不是使用循環來加入列表元素。

一個例子:

Dim list As New List(Of Integer) From {0, 1, 2, 3, 4, 5} 

MessageBox.Show(String.Format("LocID: {0}", String.Join(", ", list)), _ 
       Nothing, MessageBoxButtons.OK, MessageBoxIcon.Information) 
+0

我得到了put..if我從列表框中選擇兩個項目,我能夠在的messge框中按OK鍵兩次.. – user2878851

+0

我總是想退出messagebox,如果我按確定按鈕 – user2878851

+0

我刪除foreach ..現在我得到了正確的答案 – user2878851