I have set up Entity Framework with my VB.NET project. I have a model class that takes the data from a table from my MS SQL Server DB. My ListBox object is filled from the model class. What I am trying to do is when a user clicks on an item on from the listbox the text box is populated with the data from the table. If the user clicks on a mustang the text boxes are filled with the model, make, and year of a mustang.
I am using INotifyPropertyChanged in a viewmodel class that I thought would allow me to get each part of the dataset.
This code shows only one part of the requirements to better simplify the post
Public Class CarViewModel
Implements INotifyPropertyChanged
Private _SelectedCarModelName As CarModel
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Property SelectedCarModelName () As CarModel
Get
Return _SelectedCarModelName
End Get
Set(ByVal value As CarModel)
_SelectedCarModelName = value
OnPropertyChanged("CarName")
End Set
End Property
Public Overridable Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
My Textbox Data bind looks like this. My Textbox resides on the frm.vb.
txtCarName.DataBindings.Add("Text", _carViewModel.SelectedCarModelName.CarName, "CarName", True, DataSourceUpdateMode.OnPropertyChanged)
When I click on an item on the list it will access the property, but it will not set the property change. I know I am doing something wrong but I just don't know what it is.
******UPDATED*******
ViewModel
Public Class CarViewModel
Implements INotifyPropertyChanged
Private _SelectedCarModelName As CarModel
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Property SelectedCarModelName As CarModel
Get
Return _SelectedCarModelName
End Get
Set(ByVal value As CarModel)
_SelectedCarModelName= value
OnPropertyChanged("SelectedCarModelName ")
End Set
End Property
Public Sub OnPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class
Windows Form TextBox
**************Edited*******************
private _CarViewModel As CarViewModel
Dim bs As New BindingSource(_CarViewModel , Nothing)
txtCarName.DataBindings.Add _
("Text", bs, "SelectedCarModelName", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
After I have restarted everything, for some reason my machine likes that, I am not getting an error anymore. When I debug the code is iterating through the Getter 3x, the number of fields. but it is not getting an output for the textbox.