Hello,
I have a scenario where i have a group by column which is a concatenation of a numeric value and a string value.
But when i try to sort the column, i want the result set to be sorted on the numeric value and not on the concatenation.
There is a column in the grid which is hidden and which has the numeric values of the group by column.
I tried using the _AfterSortChange(object sender, BandEventArgs e) event and then adding the sort by
e.Band.SortedColumns.Add("NumericValues", sortIndicator == SortIndicator.Descending);
But then it removes the group by and just sorts by the numeric column. But i also want to keep the group by column.
How can i fix this scenario. Help needed please.
Thanks
Shailendra
I added the below class
class MySortComparer : IComparer {
public MySortComparer() { }
public int Compare(object x, object y) {
UltraGridCell xCell = (UltraGridCell)x; UltraGridCell yCell = (UltraGridCell)y; xCell = xCell.Row.Cells["NumericValues"]; yCell = yCell.Row.Cells["NumericValues"]; int val1 = Convert.ToInt16(xCell.Value); int val2 = Convert.ToInt16(yCell.Value); if (val1 < val2) return -1; else if(val1 == val2) return 0; else return 1;
}
and then added the below line in the _AfterSortChange(object sender, BandEventArgs e) event.
e.Band.Columns["NumericValuesAndStringValues"].SortComparer = new MySortComparer();
It works fine. But is this right and is there a better way to do it.
I am just checking about the progress of this issue. Let me know If you need my further assistance on this issue?
Thank you for using Infragistics Components.
Hello ,
What you could do is to implement IComparer interface and to add an instance of your custom implementation to GroupByComparer to the needed column. You could use IntializeLayout event of ultraGrid to assign your comparer to the desired column. On the following link you will find simple tutorial of how to do this:
http://help.infragistics.com/Help/Doc/WinForms/2014.1/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v14.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~GroupByComparer.html
also if you need custom sorting you could use SortComparer:
http://help.infragistics.com/Help/Doc/WinForms/2014.1/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v14.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~SortComparer.html
Please let me know if you have any further questions.