FlexGrid in bound mode not refreshing

Posted by: Ranba790 on 1 July 2019, 10:07 am EST

    • Post Options:
    • Link

    Posted 1 July 2019, 10:07 am EST

    Hi

    I have a flexgrid bound to a generic list of a class

    Dim DT As New List(Of clsAFE)

    gridData.DataSource = DT

    The grid display doesn’t update unless I call gridData.Refresh

    The DT is updated on different threads but only data, Item are not added or deleted.

    Any idea why the grid is not updating.

    Should I use Refresh or I need to use something else to cause the grid to display the new data after I have updated the data source data.

    Thanks

  • 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]
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels