Posted 2 July 2019, 7:24 am EST
Hello,
I will suggest you to use a BindingList instead of List as your DataSource.List does not fire events when its collection changes.The reason is List<> implements IList interface that does not provide any events for value change whereas BindingList<> implements IBindingList interface that does expose ‘ListChanged’ for changes.
You need to use Refresh() method each time whenever you made changes in the list but if you don’t want to call Refresh(), you just need to implement INotifyPropertyChanged for Class, BindingList automatically subscribes to property changes for each Class in the collection and lets the view know about the change.
Code snippet is given below : ```
Class Person
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler
Private Event INotifyPropertyChanged_PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private _FirstName As String
Private _LastName As String
Private _Age As Integer
Public Sub New(ByVal FirstName As String, ByVal LastName As String, ByVal Age As Integer)
Me._FirstName = FirstName
Me._LastName = LastName
Me._Age = Age
End Sub
Public Property FirstName As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
If _FirstName <> value Then
_FirstName = value
OnPropertyChanged(“FirstName”)
End If
End Set
End Property
Public Property LastName As String
Get
Return _LastName
End Get
Set(ByVal value As String)
If _LastName <> value Then
_LastName = value
OnPropertyChanged(“LastName”)
End If
End Set
End Property
Public Property Age As Integer
Get
Return _Age
End Get
Set(ByVal value As Integer)
If _Age <> value Then
_Age = value
OnPropertyChanged(“Age”)
End If
End Set
End Property
Overridable Sub OnPropertyChanged(ByVal [property] As String)
RaiseEvent INotifyPropertyChanged_PropertyChanged(Me, New PropertyChangedEventArgs([property]))
End Sub
End Class
Please refer to the attached sample where I have implemented the same.
Thanks and Regards,
Prabhat Sharma.
[zip filename="UpdateBoundFlexGridDemo.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-ea1f35b2-e315-45e4-afe5-b1ea1e5ace46.zip[/zip]