Hello, I'm trying to use the group by column feature with an ultragrid with different data types for the same column, but the ultragrid fails with a message "System.ArgumentException: Object must be of type XXXXX.
at System.XXXXX.CompareTo(Object value)"
The enclosed file contains a sample project that reflect the issue,
I'm using version 13.1.20131.1001
Thanks in advice,
Thanks Mike, that is exactly what we are looking for,
Hi,
The grid doesn't support this. What the grid does is - it sorts the column and then compares each pair of rows in order. The comparison is performing using the IComparable interface. The implementation of IComparable raises an exception if you try to compare a string to a double (or any two different data types, I expect).
You can probably work around this using a SortComparer, but the question is... what do you want to happen in this case. How do you compare a string to a number? Which one is less? Assuming you want to fall back on alphabetical order in such a case, you could do something like this:
ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].SortComparer = new MyGroupByComparer();
public class MyGroupByComparer : IComparer { int IComparer.Compare(object x, object y) { UltraGridCell xCell = (UltraGridCell)x; UltraGridCell yCell = (UltraGridCell)y; object xValue = xCell.Value; object yValue = yCell.Value; Type xType = xValue.GetType(); Type yType = yValue.GetType(); if (xType != yType) return xValue.ToString().CompareTo(yValue.ToString()); return Infragistics.Win.Utilities.DefaultCompare(x, y, true, false); } }