[API Proposal]: New overload on DataGridView.Sort to specify sort direction for column sort glyph icon
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### Background and motivation
Users who implement their own sort logic on a column with `SortMode=DataGridViewColumnSortMode.Programmatic` find it unintuitive/difficult to set a sort glyph icon.
See issue: #1063
This would allow a user to specify the sort glyph icon direction
### API Proposal
```csharp
namespace System.Window.Forms;
public class DataGridView
{
// Existing API
public virtual void Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction);
// New API
public void Sort (DataGridViewColumn dataGridViewColumn, ListSortDirection direction, SortOrder sortGlyphDirection);
public void Sort (IComparer comparer, DataGridViewColumn dataGridViewColumn, SortOrder sortGlyphDirection);
}
```
### API Usage
```csharp
// Sort the gridview
dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Ascending, SortOrder.Descending);
```
Existing method to achieve same outcome
```csharp
DataGridViewColumn sortColumn = dataGridView1.Columns[0];
dataGridView1.Sort(sortColumn, ListSortDirection.Ascending);
sortColumn.HeaderCell.SortGlyphDirection = SortOrder;
```
### Alternative Designs
Instead of an overload, add the `sortGlyphDirection` as an optional parameter with a default value of `SortOrder.None`.
### Risks
Could break existing application logic if optional `sortGlyphDirection` is used. But usually the glyph is set after you have sorted the gridview.
### Will this feature affect UI controls?
Yes, `DataGridView` will be affected.
Contributor guide
Assessment
This issue has not been assessed yet.