LINQ Query for the Observable Collection

I have an observable collection containing several DocumentEntry objects, each of which has a language property. I present this in a DataGrid so that documents can be updated, but this has become too many records, so I added a combo box with the names of languages, and now I need to submit only documents of this language.

Document collection is an ObservableCollection, but when I say

myDataGrid.DataContext = (from d in documents where d.language == selectedLanguage select d);

LINQ query result is not an observable collection. Am I filtering this path correctly? How can I best filter the ObservableCollection in my datagrid, in this case using the language?

Greetings

Nick

+3
source share
2 answers

CollectionViewSource.Filter

-

myDataGrid.DataContext = documents;
CollectionViewSource cvs = CollectionViewSource.GetDefaultView(documents);
vse.Filter = delegate(object obj)
{
   Document doc = obj as Document;
   if(doc == null)
       return false;
   return doc.language == selectedLanguage;
}
+1

,

XAML:

<Listbox x:name="MyLB"/>

CB:

Dim q = from c as myobject in myobservablecollection where c.CriteriaA= CriteriaB

MyLb.Itemsource =  q.ToList

: Datacontext , . LINQ, LINQ TOLIST, .

. , ToList INotifyPropertyChanged.

0

Source: https://habr.com/ru/post/1785378/


All Articles