For this (Full source)
Mockup first and last names from string list
Namespace Classes
Public Module Mocked
Public ReadOnly Property FirstNames() As List(Of String)
Get
Return {
"Alejandra", "Alexander", "Ana", "Anabela", "André", "Ann", "Annette", "Antonio",
"Aria", "Art", "Bernardo", "Carine", "Carlos", "Catherine", "Christina", "Daniel",
"Diego", "Dominique", "Eduardo", "Elizabeth", "Felipe", "Fran", "Francisco",
"Frédérique", "Georg", "Giovanni", "Guillermo", "Hanna", "Hari", "Helen", "Helvetius",
"Henriette", "Horst", "Howard", "Isabel", "Jaime", "Janete", "Janine", "Jean",
"John", "Jonas", "Jose", "José", "Jytte", "Karin", "Karl", "Laurence", "Lino", "Liu",
"Liz", "Lúcia", "Manuel", "Maria", "Marie", "Mario", "Martín", "Martine", "Mary", "Matti",
"Maurizio", "Michael", "Miguel", "Palle", "Paolo", "Pascale", "Patricia", "Patricio", "Paul",
"Paula", "Pedro", "Peter", "Philip", "Pirkko", "Renate", "Rene", "Rita",
"Roland", "Sergio", "Simon", "Sven", "Thomas", "Victoria", "Yang", "Yoshi", "Yvonne",
"Zbyszek"}.ToList
End Get
End Property
Public ReadOnly Property LastNames() As List(Of String)
Get
Return {
"Accorti", "Afonso", "Anders", "Angel Paolino", "Ashworth", "Batista", "Bennett", "Berglund", "Bergulfsen",
"Bertrand", "Braunschweiger", "Brown", "Camino", "Cartrain", "Carvalho", "Chang", "Citeaux", "Cramer",
"Crowther", "Cruz", "de Castro", "Devon", "Dewey", "Domingues", "Fernández", "Feuer", "Fonseca",
"Franken", "Fresnière", "González", "Gutiérrez", "Hardy", "Henriot", "Hernández", "Holz", "Ibsen",
"Izquierdo", "Jablonski", "Josephs", "Karttunen", "Kloss", "Koskitalo", "Kumar", "Labrune", "Larsson",
"Latimer", "Lebihan", "Limeira", "Lincoln", "McKenna", "Mendel", "Messner", "Moncada", "Moos", "Moreno",
"Moroni", "Müller", "Nagy", "Nixon", "Ottlieb", "Parente", "Pavarotti", "Pedro Freyre", "Pereira", "Perrier",
"Petersen", "Pfalzheim", "Phillips", "Piestrzeniewicz", "Pipps", "Pontes", "Rancé", "Rodriguez", "Roel",
"Roulet", "Rovelli", "Saavedra", "Saveley", "Schmitt", "Simpson", "Snyder", "Sommer", "Steel", "Tannamuri",
"Tonini", "Trujillo", "Wang", "Wilson", "Wong", "Yorres"}.ToList
End Get
End Property
End Module
End Namespace
Form code
Imports ControlBindingProject.Classes
Public Class Form1
WithEvents lastNameBindingSource As New BindingSource
WithEvents firstNameBindingSource As New BindingSource
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
firstNameBindingSource.DataSource = Mocked.FirstNames()
FirstNameComboBox.DataSource = firstNameBindingSource
lastNameBindingSource.DataSource = Mocked.LastNames()
LastNameComboBox.DataSource = lastNameBindingSource
ChangePosition()
End Sub
Private Sub BindingSources_PositionChanged(sender As Object, e As EventArgs) _
Handles firstNameBindingSource.PositionChanged,
lastNameBindingSource.PositionChanged
ChangePosition()
End Sub
Private Sub ChangePosition()
If firstNameBindingSource.Current IsNot Nothing AndAlso lastNameBindingSource.Current IsNot Nothing Then
NameTextBox.Text = $"{FirstNameComboBox.Text} {LastNameComboBox.Text}"
End If
End Sub
End Class
Now we can also use the following two classes rather than list as per above
FirstNames
Public Class FirstName
Implements INotifyPropertyChanged
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set
_name = Value
OnPropertyChanged()
End Set
End Property
Public Overrides Function ToString() As String
Return Name
End Function
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub OnPropertyChanged(<CallerMemberName> Optional ByVal propertyName As String = Nothing)
PropertyChangedEvent?.Invoke(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
And Last names
Public Class LastName
Implements INotifyPropertyChanged
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set
_name = Value
OnPropertyChanged()
End Set
End Property
Public Overrides Function ToString() As String
Return Name
End Function
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub OnPropertyChanged(<CallerMemberName> Optional ByVal propertyName As String = Nothing)
PropertyChangedEvent?.Invoke(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
Where the above as crystal clear what they are but also more than needed. Why not
Public Class GenericName
Implements INotifyPropertyChanged
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set
_name = Value
OnPropertyChanged()
End Set
End Property
Public Overrides Function ToString() As String
Return Name
End Function
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub OnPropertyChanged(<CallerMemberName> Optional ByVal propertyName As String = Nothing)
PropertyChangedEvent?.Invoke(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class