Trying to make an List or even an ArrayList that has 3 columns which I can dynamically add and retrieve elements in VB.Net.
Which I can add element like this : mylist.add(one).(two).(three)
don't know if it's possible??
Please can you help
Below is my code
I'm getting the error saying (The given key was not present in the dictionary.)
Public values As New List(Of Dictionary(Of String, String))()
values.Add(New Dictionary(Of String, String)() From { _
{"product", TextBox1.Text.Trim} _
})
values.Add(New Dictionary(Of String, String)() From { _
{"description", TextBox2.Text.Trim} _
})
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each value As Dictionary(Of String, String) In values
Dim product As String = value("product")
Dim description As String = value("description")
MsgBox(product & " - " & description)
Next
End Sub
Assuming that the data elements are all linked to one item, it sounds like you need a list of a structure.
Public Class Form1
Structure Product
Dim Id As Integer
Dim Name As String
Dim Description As String
End Structure
Dim Products As New List(Of Product)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim newproduct As New Product With {.Id = 54835, .Name = "My Greatest Product", .Description = "Blue,Large and Shiny!"}
Products.Add(newproduct)
MessageBox.Show(GetProduct(54385).Name & " - " & GetProduct(54385).Description)
End Sub
Private Function GetProduct(searchId As Integer) As Product
Return Products.Find(Function(x) x.Id = searchId)
End Function
End Class