0

I have a wpf datagrid displaying complex data. I need to be able to group the data by 3 properties simultaneously without any nesting.

Simplified example:

Id, Name, Town Visited, Date of Visit, Shop visited

I need to be able to visualise each visit and easily see how many shops were visited in that instance. To do this, I'll need to group on id,town visited and date of visit together.

Currently I have the following:

BindingListCollectionView tableData = CollectionViewSource.GetDefaultView(*datatable from sql*) as BindingListCollectionView;
tableData.GroupDescriptions.Add(new PropertyGroupDescription("Id"));

The data comes in directly from a SQL datatable and is only grouped on the Id property.

I have done extensive research on how to do the multiple grouping and the most common answers have been to place an additional property on the data object - which would require me making a new viewmodel object for every table I take from SQL (there are many) and placing a new property on each. Or creating a converter to take the datatable object and produce a group property.

I have not found a particularly helpful guide on the second option and would really rather not have to create several new view models if I don't have to.

Is there any better way to do this grouping? Can anybody explain to me how to create a converter for this if that's the best way?

Anya Hope
  • 1,301
  • 1
  • 17
  • 33
  • It seems to me that ORM is not a bad idea, and it will fit well with WPF. – dytori Oct 12 '15 at 15:50
  • Looks interesting, but also like I would still have to create separate classes for each table. I'll have a look into it but still holding out hope that there'll be a simpler solution. – Anya Hope Oct 12 '15 at 16:12
  • Actually I can not take the point: what is converter? Converting a database object results in making a new object, and works like ORM. Also, are there many tables? I presumed a single table as shown in example though simplified. I do not see any situation where distinct view models are needed. – dytori Oct 13 '15 at 00:38
  • By 'converter', I was alluding to an IValueConverter similar to the one found at http://stackoverflow.com/questions/24618966/wpf-datagrid-grouping-with-sums-and-other-fields. The number of tables is inconsequential, except that there are enough to make creating a new object for each very time consuming. I only included one in the example as I only need one grouping solution which I can then apply to each table. All tables have unique schemas and therefore would need separate view models if I were to use ORM. – Anya Hope Oct 13 '15 at 07:45
  • Converter that gives combined ID may work, but not recommended as http://stackoverflow.com/questions/6452701/wpf-datagrid-grouping-items-with-binding-converter-not-updating-dynamically – dytori Oct 13 '15 at 09:45

0 Answers0