Reputation: 123
I'm using a WPF datagrid which I binded to an OberservableCollection object to handle and display my text. I'm working with very large text files (100,000 rows and even more). While I'm able to load and display the text in the datagrid in a reasonable amount of time, I'm having issues with filtering the text.
I created a filtering function and using an ICollectionView object, assigned it to filter the text as following:
_TextLineListView = CollectionViewSource.GetDefaultView(TextLineList);
_TextLineListView.Filter = _textLineFilter;
DgText.ItemsSource = _TextLineListView;
TextLineList is my ObservableCollection object. _textLineFilter is my filtering function.
Even if my filtering function just returns "true" without any additional functionality, the loading speed of the text is significantly impacted and is much much slower.
Which other filtering methods can I use to speed things up?
Upvotes: 2
Views: 448
Reputation: 19966
You need to use DeferRefresh method.
using (_TextLineListView.DeferRefresh())
{
for (int i = 0; i < lines.Length; i++)
TextLineList.Add(lines[i]);
}
Upvotes: 0
Reputation: 123
Problem solved. If I set the filter after loading the file, loading, displaying and filtering the text is much faster
Upvotes: 1