I have a set of data where there may be 1, 2 or 3 parts of a primary piece of data. The user wants the 1,2 or 3 rows to be always grouped together, however they do not want a group by row (I've already shown them that). I've also tried an hierarchical grid and they don't want that either, because they need to look at the grid at a glance and see everything.
They want something like this:
A1A2A3B1B2C1D1D2
Now even when they click to sort any of the other columns of data, all the A's should stay together in a group.
I've been trying to figure this out for a while and I'm stumped!
Thanks in advance.
Hi,
An IGroupByEvaluator will not work here, since you are not doing any grouping.
What you need here is a SortComparer on every column in the grid.
What you would do is create a class that implements IComparer. There's only one method on this interface: Compare.
The Compare method will pass you two objects: x and y. These will be UltraGridCell objects. The first thing you will want to do is cast the objects into UltraGridCells. From there, it's an easy matter of getting the value of the column you want to sort by first. It would be something like cell.Rows.Cells["Key Column"].
What you would do then is use the cell.Value.Compare method to compare the values in the key column. If the compare method returns any non-zero values, you return that. If it returns 0, then you compare the two actual cell values being compared.
So basically, you are always sorting on the key column first, before sorting on the column the user sorted. The only time the user's sorting will ever come into play is if the values in the key column are equal.
Of course, if the key column will never have duplicate values, then the whole thing is moot, and you would be better off simply turning off sorting. :)
Sigtaupres,
As I mentioned above, you need to set the ViewStyleBand property on the grid to something other than OutlookGroupBy.This will hide "group by" header. But this will also disable default grouping of records.
So you should group rows yourself via IGroupByEvaluator.
Alex.
Alex,
So if this groups rows correctly, will they still have the standard "group by" header? With the blank line with some text that is typically the value that is grouped?
The users are very clear, they do NOT 't want any group by rows to display.
Thanks!
STP
Hi, sigtaupres.
You should put away OutlookGroupBy option:
grid.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy;
And use your own logic for grouping columns via creating a class and implement IGroupByEvaluator interface. This interface allows you to determine which rows belong in the same group and which don't. Then assign it to a column:
GroupEvaluator eval = new GroupEvaluator();grid.DisplayLayout.Bands[0].Columns["MyColumn"].GroupByEvaluator = eval;
In the next methods of GroupByEvaluator you can define your custom logic:
public object GetGroupByValue(UltraGridGroupByRow groupByRow, UltraGridRow row) { return null; // place your own logic } public bool DoesGroupContainRow(UltraGridGroupByRow groupByRow, UltraGridRow row) { return false; //place your own logic }
Note that the ICustomGroupByEvaluator will only get called to evaluate rows that are adjacent. So you may also need to implement a SortComparer on the column to make sure the column is sorted in the correct order before it is grouped.