Mykhalik
Mykhalik

Reputation: 244

Sorting columns in GridView

I use such method to sort columns in GridView

private BandedGridView bandedGridView;

public void SetControlsSortOrder(ColumnSortOrder sortOrder)
        {
            bandedGridView.BeginDataUpdate();
            try
            {
                bandedGridView.SortInfo.ClearSorting();
                bandedGridView.SortInfo.Add(new GridColumnSortInfo(colName, sortOrder));
            }
            finally
            {
                bandedGridView.EndDataUpdate();
            }
        }

When sortOrder is Ascending or Descending method works fine, but when sortOrder is None columns in table is sorted by descending. Could you help me solve this problem?

Upvotes: 0

Views: 941

Answers (1)

nempoBu4
nempoBu4

Reputation: 6631

If your colName is grouped then its sort order cannot be set to ColumnSortOrder.None value and your column using the last sort order that was applied to it. If your colName is not grouped then check for sort glyph if you see sort glyph then sorting is applied to your column. If you can not see sort glyph then your DataSource is coming already sorted as mentioned by Burak Ogutken.

Also, for sorting use BandedGridView.BeginSort and BandedGridView.EndSort methods. To set the sort order you simply can use the BandedGridColumn.SortOrder property. To clear sorting you can use BandedGridView.ClearSorting method.
Here is example:

public void SetControlsSortOrder(ColumnSortOrder sortOrder)
    bandedGridView.BeginSort();
    try {
       bandedGridView.ClearSorting();
       colName.SortOrder = sortOrder;
    }
    finally {
       bandedGridView.EndSort();
    }
}

Upvotes: 2

Related Questions