Hello,
I use group by Mode in WinGrid (Infragistics 8.3)
I need to group by records accroding to column A but I neeed to sort them by the summary value of column B when I click on the header of column B.
I have created my own Groub By Comparer but I do not manage to enter in it when click on the header of a column. It is the same problem after overriding the HeaderClickAction of this column with SortSingle or SortMulti..
The problem is I cannot manage to enter in the GroupByComparer of my column. How can I do that ?
(In fact I enter in the GroupByComparer only ath the loading on my group By Rows in the method Infragistics2.Win.UltraWinGrid.v8.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.InitGroupByRows() + 0x16a bytes )
How can I enter in this InitGroupByRows method I click on the Header of a column ?
Thx
When you click on a header, the GroupByComparer isn't used as this is only utilized when peforming the actual grouping. You would need to implement the IComparer interface and set it on the SortComparer property of the column.
-Matt
In fact I have also defined a SortComparer but I cannot enter in it when i am in group by mode.
I have tried several header click action mode and it is always the same thing. I manage to enter in my own comparers only when the group by is build.
Do you know a way to enter in the compare Method of a SortComprarer/groupbycomparer ? ( I could use it in the BeforeSortChange of my grid )
I'm not quite sure that I understand what your question is. Are you saying that the SortComparer property of a column is ignored when they are children of a GroupByRow? I just tested this out, and the only time that the SortComparer property was ignored for an ungrouped column was when there was only a single row in the Rows collection (i.e. the GroupByRow had a single child).
In fact it is true that in my example I had one child row in each GroupByRow.
The point is that I want to sort the GroupByRows not the child rows inside each groupByRow.
It is why I firt wanted to use the GroupByComparer.
How can I do that ?
Perhaps I was misreading the original question then. The GroupByComparer should be sorting the GroupByRows when the column that the comparer is assigned to is grouped. I tested this in a quick sample application and my sort comparer was correctly being used when I clicked on the column in the GroupByBox to sort. Are you sure that your comparer isn't being hit? The following code worked for me:
public class GSC : IComparer{ public int Compare(object x, object y) { return ((IComparable)((UltraGridGroupByRow)x).Value).CompareTo(((UltraGridGroupByRow)y).Value); }}
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].GroupByComparer = new GSC();
Obviously this is a hack comparer, but it was good enough for the test and was properly being hit for sorting. Perhaps if you post what you are doing and what you're seeing, I can test it out.
It does not work me. I precise that I do not want to sort by clicking in a column header in the group by zone but according to a non group by column (which has summary values).
I am sorry if my question was not clear. :$
Thanks
RefreshSort should cause the Comparer to get called again. But again, this might be an issue with the fact that you are using BeforeSortChange.
Just as a test, what if you put a button on the form and call RefreshSort there?
If that works, then it confirms my suspicion that this is a timing issue. If that's the case, then there are a couple of possible solutions.
One would be to make the sorting synchronous. There's a property on the BeforeSortChanged event args for this. Then you could try calling RefreshSort inside the AfterSortChange event. You will probably want to set a flag or something so that you only do this when you need it.
If that doesn't work, then I would try the same thing, but instead of calling RefreshSort directly inside AfterSortChanged, use BeginInvoke to call a method that calls it. That will institute another delay that might help.
The reason why I did it inside BeforeSortChange instead of InitializeLayout is that I wanted to modify the GroupByComparer based on what column the user is attempting to sort by. Strangely, my code works only the first time a column is sorted.
Here is what I mean: Lets say we have 3 columns, "Name", "X", "Y". X and Y are numeric and have group-by row summaries on them. The user groups by Name, and would now like to sort the groups by the X-summary. So they click on X header, and inside the BeforeSortChange I create a GroupComparer(X) that knows to use the X-summary for its Compare method. This works fine the first time, but when the user clicks on the X header again (to change sort direction), nothing happens - the BeforeSortChange event is called but Compare is not. However, if I go and sort by Y-summary, and then come back and sort by X-summary, it works again. I am calling SortedColumns.RefreshSort(true), which is supposed to re-create the groupings, but its as though it has no effect on the 2nd click.
I'm not sure that setting the GroupByComparer inside BeforeSortChange is a good idea. You may want to set it earlier, like in the InitializeLayout event of the grid.
Also, the GroupByComparer will not be called unless the column is actually grouped. If it's just sorted, then there's no need to call the Comparer. Is the column grouped in this case?
Sorry to hijack an old thread here, but I think I am having the same issue as pebg. I've created a custom class implementing IComparer and then set the GroupByComparer property inside the BeforeSortChange event as follows:
col.GroupByComparer = new GroupComparer(sortByColumn);
where GroupComparer is my custom class. I see the BeforeSortChange even being called, and the GroupByComparer seems to be set correctly, but then my custom Compare method never gets called. I've tried:
e.Band.SortedColumns.RefreshSort(true);
but it does not help.
Any ideas please?
No it does not work. It enters in the beforesortchange handler but not in the COmpare method of the group by comparer.