从ListBox中获取信息并将其放入标签
问题描述:
基本上,我在写这个Visual Basic(VB6)应用程序中有一个ListBox
。 ListBox
包含“观看的电影”。从ListBox中获取信息并将其放入标签
我希望能够抓住这个ListBox中的所有项目,并将这些项目放入标签中。但我无法弄清楚如何从我的ListBox中获取信息到我的标签。
任何帮助将不胜感激,谢谢!
答
我不熟悉VB,所以我不能给你任何代码。
只是运行所有的项目,并做myLabel.Content = myLabel.Content + myListBox.Items[i].Text
。
答
Dim ListText As String
Dim Counter As Integer
ListText = ""
For Counter = 0 To List1.ListCount - 1
If List1.Selected(Counter) = True Then
ListText = ListText & List1.List(Counter) & vbCrLf
End If
Next
MsgBox ListText
答
这将采取从列表框中的一切,并将其添加到标签,如你问你的问题。如果您只想将选定项目放入您的标签中,请使用SpectralGhost的答案。
Dim x As Integer
List1.AddItem ("Hello")
List1.AddItem ("World")
For x = 0 To List1.ListCount - 1
Label1.Caption = Label1.Caption + List1.List(x) + vbCrLf
Next
你有什么试过的?你能发布你的代码并解释你在哪里遇到困难吗? – Oded
这是VB.NET吗? – Ryan
这是VB6。我真的没有尝试太多,因为我很迷茫,哈哈。我有我的信息构建我的列表框。 – user1055519