Hello:
I understand how to bind data to a ComboBox programmatically:
For Example:
ComboBox1.DataSource = data.EmployeeList()
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "EmployeeID"
However, what I am attempting to do is bind data using the designer and a Binding Source Object.
As demonstrated below, using the designer I added a data source and configured the display and value member but there is no data when the form loads.
How do I bind a list using the designer to a Combobox?
What I have tried:
First I created a Data Source:
Public Class Employee
Public Property EmployeeID As String
Public Property Name As String
End Class
Public Class Data
Public Function Data() As List(Of Employee)
Return New List(Of Employee)() From { _
New Employee() With { _
.Name = "George Benson", _
.EmployeeID = 321
}, _
New Employee() With { _
.Name = "Gladys Knight", _
.EmployeeID = 322
}, _
New Employee() With { _
.Name = "David Bowie", _
.EmployeeID = 323
}, _
New Employee() With { _
.Name = "Steve Wonder", _
.EmployeeID = 324
}, _
New Employee() With { _
.Name = "Tina Turner", _
.EmployeeID = 325
}
}
End Function
End Class
Next I created a View Model with a single read only property so that I can bind the
ComboBox to it.
Note: this is not full implementation of MVP Or MVPM, this is for demonstration only.
Public Class EmployeeViewModel
Private _listEmployees As Data
Sub New()
_listEmployees = New Data()
End Sub
Public ReadOnly Property EmployeeList() As List(Of Employee)
Get
Return _listEmployees.Data()
End Get
End Property
End Class