I want to fill a combobox from a dictionary source. This dictionary has a class value and I want to use the class properties for combobox values.
Example class
Public Class Customer
Public ID As Integer
Public Name As String
Public Address As String
Public City As String
Public Sub New(ByVal newID As Integer, ByVal newName As String, ByVal newAddress As String, ByVal newCity As String)
ID = newID
Name = newName
Address = newAddress
City = newCity
End Sub
End Class
Example form
Public Class Form1
Dim Customers As New Dictionary(Of Integer, Customer)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Customers.Add(341, New Customer(341, "Michael", "Street 52", "New York"))
Customers.Add(149, New Customer(149, "Susan", "Street 12", "Los Angelos"))
Customers.Add(721, New Customer(721, "Bill", "Street 98", "Houston"))
Customers.Add(958, New Customer(958, "Jeff", "Street 54", "Washington"))
ComboBox1.DataSource = Customers 'What to use as a datasource??
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "ID"
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
MsgBox(ComboBox1.SelectedValue)
End Sub
End Class
How to set the ComboBox1 properties so that I can see the customer name as DisplayMember
and it's ID as ValueMember
?