Hi,
I have a use case which is explained as follows:
"I have a UltragGrid which has some 10 column. But I need two types of sorts for these columns. i.e Some columns need default sorting provided by UltraGrid, and some other columns requires Three Way Sorting."
Three Way Sorting in my point of view is:
a. Ascendiing -Indicated by default ascending SortIndicator.
b. Descending- Indicated by default descending SortIndicator.
c. Absolute Descending: shoudl be indicated by a + sign.
I am new to the Infragistics. Can anyone help me in getting this with a nice example.
Thanks very much in advance.
Sanjeev.
Hi Sanjeev,
There's nothing like this built-in to the grid.
There are basically three issues here:
1) Sorting the grid in a custom order - this is very easy to do. You just need to write a custom IComparer class and assign it to the SortComparer property of the column.
2) Showing a plus sign - this is a little more difficult. You would have to use a CreationFilter or a DrawFilter to replace the existing sort indicator in the column header with a different image.
3) Toggling the sorting three ways - To do this, you would have to handle the events of the grid like BeforeSortChanged. When going from Ascending to Descending, there would be no problem - you can just do nothing and let the grid handle it. But the transition from Descending to Absolute Descending would require you to prevent the SortIndicator property on the column from changing and instead just attach the SortComparer. You would also have to handle the transition from Absolute Descending to Ascending and remove the SortComparer.
None of this is trivial, especially if you are new to the grid, but it should all be possible, I think.
Hi Mike, I tried out this. Unfortunately I haven't succeeded. 1. Sorting the grid in a Custom order I wrote following Comparer where it is valid only for absolute descending sorting. But I found that this is not at all called even if I set SortComaparer to the column. private class MySortComparer : IComparer { internal MySortComparer() { } int IComparer.Compare(object x, object y) { UltraGridCell xCell = (UltraGridCell)x; UltraGridCell yCell = (UltraGridCell)y; double value1 = Double.Parse(xCell.Value.ToString()); double value2 = Double.Parse(yCell.Value.ToString()); return (Int32)(Math.Abs(value1) - Math.Abs(value2)); }}3. Toggling the sort:Here is the code for setting this sort comparer.private void ultraGrid_BeforeSortChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSortChangeEventArgs e){ if (!(e.SortedColumns[0].Key.Equals("Value"))) { // // I want this kind of sorting for only "Value" column. // return; } // // I am sure that I have single column sorting // UltraGridColumn column = e.SortedColumns[0]; SortIndicator indicator = column.SortIndicator; // // Moving from Descending to Ascending. Here we need to move to AbsoluteDescending. // if (indicator == SortIndicator.Ascending) { MySortComparer sortComparer = new MySortComparer(); column.SortComparer = sortComparer; //column.SortIndicator = SortIndicator.None; // // If I uncomment the above statement, I am getting Exception where it is saying that we can't change // SortIndicator in BeforeSortChage Event // } // // Moving from Ascending to descending. We won't need any customization here // else if (indicator == SortIndicator.Descending) { Console.WriteLine("going from ascending to descending "); } // // Assuming that we should come from absolute descending to ascending. // else { // // Need to remove SortComparer. // column.SortComparisonType = SortComparisonType.Default; //column.SortIndicator = SortIndicator.Ascending; }}2. Showing a Plus Sign: I have written a DrwaFilter class to draw + Symbol. Instead of getting through an image, I am just drawing the + symbol. But I have obderved that it is drawing every time even if column is in ascending mode or descending mode. public class Sort_Order_Indicator_DrawFilter : IUIElementDrawFilter { #region IUIElementDrawFilter Members bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { if (drawPhase == DrawPhase.AfterDrawElement) { HeaderUIElement headerUIElement = drawParams.Element as HeaderUIElement; if (headerUIElement != null) { UltraGridColumn column = drawParams.Element.GetContext(typeof(UltraGridColumn)) as UltraGridColumn; using (Font font = new Font("Arial", 14)) { using (SolidBrush solidBrush = new SolidBrush(Color.Black)) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Far; stringFormat.LineAlignment = StringAlignment.Near; DrawStringParameters drawStringParameters = new DrawStringParameters( drawParams.Graphics, "+", font, solidBrush, headerUIElement.Rect, stringFormat, GdiDrawStringFlags.GDIPlus, TextOrientationInfo.Horizontal); // Draw the string. DrawUtility.DrawString(ref drawStringParameters); } } } } return false; } DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { // Trap for a HeaderUIElement if (drawParams.Element is HeaderUIElement) { UltraGridColumn column = drawParams.Element.GetContext(typeof(UltraGridColumn)) as UltraGridColumn; if (column != null && (column.SortIndicator == SortIndicator.Ascending || column.SortIndicator == SortIndicator.Descending)) { return DrawPhase.AfterDrawElement; } } // Do nothing. return DrawPhase.None; } But I am thinking that I should have one more value for SortIndicator enum which tells about the status of absolute sorting. With the help of this, in GetPhasesToFilter we will return true only incase of Absolute Sorting mode so that it will draw + sign. I tried alot to get this. Can you please tell me (if possible a small example) to get this done. Thanks very much. Sanjeev.