2010-07-12 28 views
4

我有2個可用於行區域的字段。其中一個是「ID」,另一個是「名稱」。將它們放入行區時,按ID和okey排序。但是當我把「名稱」字段放到那裏時,它按值排序。ASPxPivotGrid排序

我想按ID排序而不顯示,但還沒有克服。

Here the documentatio n但它不是很清楚可以解決我的問題。

有誰知道如何解決它?

編輯:例子:

alt text http://community.devexpress.com/forums/214248/PostAttachment.aspx

回答

1

這裏是應該爲你工作的代碼:

private void pivotGridControl1_CustomFieldSort(object sender, DevExpress.XtraPivotGrid.PivotGridCustomFieldSortEventArgs e) { 
    if(e.Field.FieldName == "Name") { 
     int value1 = Convert.ToInt32(e.GetListSourceColumnValue(e.ListSourceRowIndex1, "ID")); 
     int value2 = Convert.ToInt32(e.GetListSourceColumnValue(e.ListSourceRowIndex2, "ID")); 
     e.Result = Comparer.Default.Compare(value1, value2); 
     if(e.SortOrder == DevExpress.XtraPivotGrid.PivotSortOrder.Descending) 
      e.Result = -e.Result; 
     e.Handled = true; 
    } 
} 

是否行得通?

+0

感謝您的解釋! – GianlucaBobbio 2013-09-24 15:59:59