novacara
novacara

Reputation: 2257

WPF Filter Datagrid

I have a datagrid that I want to filter based on a value selected from a combobox. The source of the datagrid is an XML file. Below is the code I am using. When I trace the code the view filter is returning true and false correctly for each row but the datagrid never updates. What simple thing am I missing?

ComboBoxItem typeItem = (ComboBoxItem)cbPositionFilter.SelectedItem;
String position = typeItem.Content.ToString();

IEnumerable<XElement> playersSource = ((XContainer)AllPlayers.DataContext).Descendants("Player");
ICollectionView view = CollectionViewSource.GetDefaultView(playersSource);

 view.Filter = delegate(object item)
 {
       bool match = ((XElement)(item)).Element("position").Value == position;
       return match;
 };

Upvotes: 0

Views: 1663

Answers (1)

Dan J
Dan J

Reputation: 16718

Is your DataGrid bound to playersSource, or view? If you're doing the former, try the latter. :)

Upvotes: 1

Related Questions