K
K
kodwi2014-08-15 21:45:46
WPF
kodwi, 2014-08-15 21:45:46

Who can tell me how to work with CollectionView / CollectionViewSource in WPF?

Faced a problem of work with the data bound to DataGrid. It is necessary to implement automatic updating of source elements, data validation, grouping, filtering. Everything should be generated in code (no writing in XAML). To be honest, I'm just confused - what to use for what: ObservableCollection / CollectionView / CollectionViewSource, what to inherit from, etc. In Google, the information is very scarce. Can someone on skype advise on the implementation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deerenaros, 2014-08-16
@Deerenaros

I can google and here. It's not good to leave contacts, so at least hide them in the comments, I'll get in touch.
Ok, in short, there is an ObservableCollection, and when you create a collection, you then equate it to DataGrid.ItemSource:

struct Some {
    String a;
    int b;
}

/***/
DataGrid dataGrid = /***/;
ObservableCollection<Some> s = new /***/;
s.Add(new Some{a = "A", b = 1});
s.Add(new Some{a = "B", b = 2});
/** forget how to bind struct to data grid, check below**/
dataGrid.ItemSource = s;
/***/

Link to Siberia.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question