开发者

ASPxPivotGrid Sorting

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 i开发者_如何转开发t 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 http://community.devexpress.com/forums/214248/PostAttachment.aspx


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜