views:

115

answers:

0

Hi, I've setup data binding in VB.NET as follows with an Address business object and a Textbox. My issue is when I use

AddressObjectInstance.Name = "Bob"

the text box will update while if I do

AddressObjectInstance = AnotherAddressObject

the text field does not update. How do I force them to update properly?

My Address Object:

Public Class Address
    Implements INotifyPropertyChanged

    Private _Name As String

    Public Event PropertyChanged As PropertyChangedEventHandler _
      Implements INotifyPropertyChanged.PropertyChanged

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub

    Public Property Name()
        Get
            Return _Name
        End Get
        Set(ByVal value)
            If value <> _Name Then
                _Name = value
                NotifyPropertyChanged("Name")
            End If
            _Name = value
        End Set
    End Property
End Class

Form Load Data Binding:

txt_name.DataBindings.Add("text", CurrentAddress, "Name")

Object Instance Declaration:

Dim CurrentAddress As Address = New Address("")
'The constructor allows for you to set default values.

This will work:

CurrentAddress.Name = "Bob"

This will not work:

CurrentAddress = SomeotherAddress