Sorting tables with SortMemberPath using ValueConverters?

Feb 4, 2010 at 3:59 PM

Hi,

I have a datagrid where the cells containing an object and the correct value is displayed through a converter. Every column is a Templatecolumn and is generated during runtime. When I try to implement a sorting on these columns through the SortMemberMath-Property, the columns will be sorted but not in a alphabetically way. In my opinion the problem is the converter of the cells and the sorting tries to sort the objects in the cells and not the value of the cell. But the SortMemberPath-Property does not support any Converter. How can I achieve to sort my tables in this situation?

 

Thx in advance

Feb 6, 2010 at 12:57 PM

Hi

I've got a similiar column implementation - custom object as a cell Content with many converters used for displaying some data from that object. The easiest way of implementing sorting (if you are sure that SortMemberMath is set properly, especially when you have bindings) is to implement IComparable interface in the class of your Property. It's enought to implement CompareTo(object o) method, depending on your needs. You can also implement Equals(object o).

 

Feb 8, 2010 at 11:40 AM

Thanks for this hint. Now I have implemented the IComparable interface to my object and set the SortMemberPath to the Property who gets this object. This works fine now.