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 Reply Children
No Data