从报告中删除排序字段

时间:2018-11-07 11:20:24

标签: c# .net crystal-reports

我正在将Crystal Reports与C#一起使用,并且有一种方法可以添加新的Sort字段来报告:

public void AddSortField(string fullFieldName, string direction = "ASC")
{
    string[] fieldSplitted = fullFieldName.Split('.');
    string tableName = fieldSplitted[0].ToUpper();
    string fieldName = fieldSplitted[1].ToUpper();
    DatabaseFieldDefinition fieldDefinition = reportDocument.Database.Tables[tableName].Fields[fieldName];

    // ...
    // Long code to add firstly the fieldDefinition to collection of Sort Fields.
    // ...


    int sortFieldsCount = reportDocument.DataDefinition.SortFields.Count - 1;
    reportDocument.DataDefinition.SortFields[sortFieldsCount].Field = fieldDefinition;
    reportDocument.DataDefinition.SortFields[sortFieldsCount].SortDirection = direction == "ASC" ?
        SortDirection.AscendingOrder :
        SortDirection.DescendingOrder;
}

现在我需要一种方法来从SortFields中清除一个字段/所有字段,但是我不知道从哪里开始。尝试了这个没有成功:

public void ClearSortFields()
{
    int sortFieldsCount = reportDocument.DataDefinition.SortFields.Count;

    for (int i = 0; i < sortFieldsCount; i++)
    {
        reportDocument.DataDefinition.SortFields[i].Field = null;
    }
}

如何清除C#(.NET)Crystal Reports中的排序字段?

0 个答案:

没有答案