I have a custom object collection, which needs to be grouped by and sorted with some properties in the ultraWinGrid (version 8.1). These objects contain properties namly "createdDate" and "CreatedDetails". I want to group these items with CreatedDate but display the groupheader as createdDetails. Also the groups should be in chronological order of ascending/descending order of the CreatedDate.
How can i achieve this, comparing with one property and displaying another corresponding property as header.
One solution i thought was having a custom class instance within these objects, as described below. I implemented the IComparable Interface, so that it compares with the Date to sort and for display i override the ToString() method. and i say
dataGrid1.DisplayLayout.Bands[ 0 ].SortedColumns.Add( "RecordCreationDetail ", false, true );
but still it compares with the CreatedDetails and groups by string comparision of this and not group by CreatedDate.
Help Please.
public class RecordCreationDetail : IComparable<RecordCreationDetail>{ private DateTime _createdDate; public DateTime CreatedDate { get { return _createdDate; } }
private string _createdDetails = String.Empty; public override string ToString() { return _createdDetails; }
public RecordCreationDetail( DateTime createdDate, string createdDetail ) { _createdDate = createdDate; _createdDetails = createdDetail; }
#region IComparable<CreatedDetail> Members public int CompareTo( RecordCreationDetail other ) { return DateTime.Compare( this._createdDate, other._createdDate ); } #endregion}
Hi Mike,
Thanks for the tips. Yes i got the result as doing following
recordCreationDetailCol.GroupByMode = GroupByMode.Value;
recordCreationDetailCol.SortComparer = new RecordCreationDetailRowsSorter();
And this RecordCreationDetailRowsSorter is a class implementing the IComparer
public class RecordCreationDetailRowsSorter : IComparer
{
// Do Custom Sorting of the cell object values
}
Hi Arif,
Everything I write in my previous post still applies.
In order to sort this column you will either have to implement a SortComparer on the column or implement IComparable on the RecordCreationDetail class.
To group it, you will need to implement a GroupByEvaluator (although the SortComparer might take care of this automatically, I am not sure).
In order to sort the GroupByRows, thenselves, you will need to creaet a GroupBySortComparer.
Yes, Am binding the grid with a list of objects. And these objects have a one of their memberVariable of type "RecordCreationDetail " object.
So the object "RecordCreationDetail" is actually stored in a cell(binded to a column) and this cell object(column object) has two properties "CreatedDate" and "CreatedDetails". And i want to do grouping and sorting of my lists based on this object values. And i want to Group my list of objects by the "CreatedDetails" value, but then i want them to be in order of "CreatedDate".
Something like below, where the grouping text is the "CreatedDetails" but the sorting of the same groups is thru "CreatedDate".The latest group of transactions being at the bottom.
GroupRow - Detail : 09/02/2007; User1 ; Other Stuff.
Datarows.....
GroupRow - Detail : 09/12/2007; User2 ; Other Stuff.
GroupRow - Detail : 09/02/2008; User3 ; Other Stuff.
I will try with the properties you mentioned, but then if you are now clear about the scenario, can you give a quick insight, how to achieve the same.
Thanks,
Arif
I'm a little unclear on how your grid is set up. Are you binding to a list of these objects? Or is the object you are referring to here stored in a single cell?
Either way, you should be able to acheive what you want. You can group the grid by whatever column you choose and then determine the text of the GroupByRow in one of two ways:
If you need finer control over the actual grouping, you can use the GroupByEvaluator property on the column.
If you need finer control of the sorting, you can use the SortComparer on the column (note that this only applies to data rows, not GroupByRows).
If you need to control the sorting of the GroupByRows, there is a GroupBySortComparer on the column.