45
IComparer - Comparing values from the DataRecord instead of the CellValue
posted

Hello,

We are using a XamDataGrid with a number of columns, but no grouping. One of the columns must be sorted, not by the values in the column, but by another value from the same DataRecord.
I've looked at the following posts:

https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/75182/sort-groupby-coulmn-by-value-of-another-column-in-xamdatagrid
https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/76675/icomparer---pass-datarecord-instead-of-cellvalue

The mentioned solution is interesting.
However, these only seem to work when grouping.
Is it possible do this without grouping, and to pass the DataRecord to the ICompare function instead of the cell values?

Thanks!

P.S. our current ICompare function is as follows. The objects are always strings, which means the cast never works.

// TODO: this only compares strings, not the totalStatusWeight
public int Compare(object o1, object o2)
{
 var item1 = o1 as ControlTowerOrderItem;
 var item2 = o2 as ControlTowerOrderItem;
 if (item1 == null || item2 == null)
  return 0;

 return item1.TotalStatusWeight.CompareTo(item2.TotalStatusWeight);
}