tags:

views:

33

answers:

1

I have 2 fields that can be use in row area. One of them is "ID" and the other one is "Name". When put them in to row area, it is sorted by ID, okey. But when I just putted "Name" field to there it is sorted by value.

I'm trying to sort it by ID without displaying but haven't overcome yet.

Here the documentation but it is not very clear that can solve my problem.

Does anybody know how to solve it?

EDIT: Example:

alt text

+1  A: 

Hi,

Here is the code which should work for you:

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;
    }
}

Does it work?

DevExpress Team