Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
405
Groupby and sortby with related entities.
posted

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
}

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    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:

    1. Use the GroupByRowDescriptionMask property.
    2. Handle the InitializeGroupByRow event and set the Description property on the GroupByRow.

    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. 

Children