Reputation: 31
I seem to not getting it, I'm trying to create some kind of list in Visual Basic where each item isn't just a string but a bundle of labels, a button and maybe a picture. I've already written some programs in VB but I just don't get how I'm supposed to start this, sorry, maybe I'm just missing out some elements or something like that. Anyone got an idea?
Upvotes: 1
Views: 5496
Reputation: 250
This is highly simplified, and for illustration only.
I've created a class that is nothing more than 2 properties to hold pointers to a related set of 1 button and 1 textbox.
Public Class MyControls
Property theTextBox As TextBox
Property theButton As Button
End Class
Then in my code that needs to store the controls together in a list:
Dim controlList As New List(Of MyControls)
Dim item1 As New MyControls
item1.theButton = New Button
item1.theTextBox = New TextBox
controlList.Add(item1)
After than you can get access to the controls by selecting the items from the list and using the dot operator.
controlList.Item(0).theTextBox.Text = "New text"
Adding these to a ListView depends on how you want them displayed. The hard part is deciding there to put them... This example just adds the textbox and displays the button below it.
controlList.Item(0).theButton.Text = "press me"
ListView1.Controls.Add(controlList.Item(0).theTextBox)
controlList.Item(0).theButton.Top = controlList.Item(0).theTextBox.Height
ListView1.Controls.Add(controlList.Item(0).theButton)
Upvotes: 2