This example demonstrates how to allow columns to fit their content after changing or modifying GridControl's ItemSource.
To provide this capability in this sample, we iterate through GridControl's ItemsSource collection and subscribe to the PropertyChanged event of each item in this collection. Then we subscribe to GridControl's ItemsSourceChanged event, get GridControl's ItemsSource collection and subscribe to its CollectionChanged event. When one of these events is raised, we call TableView's BestFitColumns method. Please note that GridControl's ItemsSource collection must support the INotifyCollectionChanged interface and each item in this collection must support the INotifyPropertyChanged interface.
Question Comments
Added By: Quentin Suckling at: 5/5/2015 6:24:34 PM
Hi guys,
When the view is closed and the grid unloaded, will the CollectionChanged and/or the ItemsSource events get fired?
If not, I'm guessing it would need to subscribe to the Unload event and then unsubscribe to the PropertyChanged event otherwise it won't be GC'd?
Cheers,
Quentin
You are correct, the current implementation can lead to memory leaks since we don't unsubscribe from the PropertyChanged/CollectionChanged events. You can unsubscribe from them in the Unloaded event handler. Feel free to contact us if you face issues with this approach.