分组问题

时间:2011-08-18 09:32:06

标签: c# devexpress

我有以下代码(DevExpress组件):

dgvDisplayDictionary.DataSource = DataAccessor.GetAllRecords();

gvDisplay.BeginSort();
gvDisplay.ClearGrouping();
gvDisplay.Columns[0].GroupInterval = ColumnGroupInterval.Alphabetical;
gvDisplay.Columns[0].GroupIndex = 0;
gvDisplay.EndSort();

我收到以下错误:

At least one object must implement IComparable.

我的类绑定到gvDisplay

public class NormDocCost:AbstractDisplayDictionary.
    {            
        public virtual Category Category { get; set; }            
        public virtual DocumentFormat DocumentFormat { get; set; }            
        public virtual Translate Translate { get; set; }
        public virtual int NdcId { get; set; }           
        public virtual int PageStart { get; set; }         
        public virtual int PageEnd { get; set; }          
        public virtual double Cost { get; set; }            
        public virtual DateTime? DateFrom { get; set; }            
        public virtual DateTime? DateTo { get; set; }
   }

我试图编写此代码,但不起作用:

public int CompareTo(object other)
        {
            var obj = (NormDocCost)other;
            if(obj.Category.Id == Category.Id)
            {
                return this.Category.NameRu.CompareTo(obj.Category.NameRu);
            }
            return obj.Category.Id.CompareTo(Category.Id);
        }

1 个答案:

答案 0 :(得分:1)

当网格组记录时,它首先对它们进行排序,然后仅根据组列中具有相同值的行创建组。所以,我倾向于认为第一列绑定到Categbory字段。它的类型是什么?我认为网格无法比较此字段的值,因此会引发此异常。