Hi
I am trying to change the data in a selected node using the following code:
Private Sub OrgChart_NodeMouseRightButtonDown(sender As Object, e As Infragistics.Controls.Maps.OrgChartNodeClickEventArgs) Handles OrgChart.NodeMouseRightButtonDown
Dim employee As Employee = DirectCast(e.Node.Node.Data, Employee)
employee.Name = "Fred Smith"
End Sub
I cannot seem to get the node to show the new data - is there a Refresh method or something else I can use?
Thanks
Andrew
Hi Andrew,
There's nothing wrong with the code you're using so what it looks like you are missing are the INotifyPropertyChanged events on your properties. This will update your node automatically.
Hi Rob
I have added the INotifyPropertyChanged as follows:
Public Class Employee
Implements INotifyPropertyChanged
....
Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
But still nothing changes - unless I click on the Expanded icon for any node when the new Name appears.
Do I need to add code to the OrgChart.PropertyChanged event?
That's only the first part of implementing INotifyPropertyChanged. You need to manually trigger the event on your properties when they are changed. The typical place to do this is in the property's setter. See the example below what your Name property would look like.
Public Property Name() As String Get Return _name End Get Set(ByVal value As String) If Not _name = value Then _name = value OnPropertyChanged("Name") End If End Set End Property Protected Sub OnPropertyChanged(ByVal name As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name)) End Sub
Many thanks again - this did the trick!
Regards
I'm glad it's working for you now. Let me know if you have any further questions on this matter.