Hi,
I am playing a little bit with the DataGrid. I found the ICollectionView which allows filtering and grouping, but based on reflection. I know how to filter ObservableCollections, no problem there.
But currently I am a little bit stuck with the grouping feature. I want to use the DataGrid to display the data grouped by Names. Or Numbers. As I said, currently testing...
The problem is, I do not want to do it in XAML. There are some examples on how to teach the DataGrid grouping in XAML, but I need a more flexible approach. But I do not quite understand the grouping feature of the ObservableCollection and if it should "automatically" work with the DataGrid.
My Source so far (the important part) is:
public class DataContainer
{
public string Name { get; set; }
public Type TypeVar { get; set; }
public int Number { get; set; }
public Class GroupClass { get; set; }
}
public class CustomDataGrid : UserControl
{
public ObservableCollection<DataContainer> DataItems { get; set; }
public CustomDataGrid(ObservableCollection<DataContainer> dataItems)
{
DataItems = dataItems;
DataItems.GroupBy(x => new {x.Name });
Afterwards I just create a DataGrid and bind the Itemssource to the DataItems collection. Filtering is working, but I am stuck how to use the grouping.To save anyone some time, I do not need a complete detailed explanation, I am normally good at reverse engineering. So if anyone figured out the grouping, how would the code above look (the last line) to:
A) Group the collection by Names
B) Group the Collection by Names first, and then inside this, by Numbers
I think with these two examples I could figure out the rest..
Christian
PS: Perhaps my approach is completely wrong. If so, correct me. What I want to create is an universal DataGrid for my DataContainer which can be filtered, grouped and sorted without the use of XAML and NO magic string (the reflection filter of ICollectionView looks "evil")