winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Sort glyph icon should be shown in DataGridView column header cell when programmatically sorted DataGridView

Open Olina-Zhang opened this issue 5 years ago • 2 comments

  • .NET Core Version: .NET Core 3.0 3.0.100-preview6-012102 from master branch
  • Have you experienced this same bug with .NET Framework?: Yes

Steps to Reproduce:

  1. Open this attached Core app, build and run it WindowsFormsApp6.zip
  2. Click "SortColumn1" or "SortColumn2" button to sort left DataGridView, which Columns' SortMode is "Programmatic"
  3. Please notice corresponding sort Column header

Actual behavior: There is no sort glyph icon showing in Column header. image

Expected behavior: It should have sort glyph icon showing in Column header when sorting it, like sort DataGridView with "Automatic" SortMode setting. image

Olina-Zhang avatar May 29 '19 09:05 Olina-Zhang

@Olina-Zhang Is this a regression from an earlier .NET Framework version, or have we always had an issue when users try to problematically set the sort?

merriemcgaw avatar May 29 '19 23:05 merriemcgaw

@merriemcgaw This is not a regression issue. Earlier .Net framework versions all have this issue when setting SortMode as Programmatic.

Olina-Zhang avatar May 31 '19 03:05 Olina-Zhang

You can sort a DataGridView programmatically by the values in any column or in multiple columns, regardless of the SortMode settings. Programmatic sorting is useful when you want to provide your own user interface (UI) for sorting or when you want to implement custom sorting. Providing your own sorting UI is useful, for example, when you set the DataGridView selection mode to enable column header selection. In this case, although the column headers cannot be used for sorting, you still want the headers to display the appropriate sorting glyph, so you would set the SortMode property to Programmatic.

Columns set to programmatic sort mode do not automatically display a sorting glyph. For these columns, you must display the glyph yourself by setting the DataGridViewColumnHeaderCell.SortGlyphDirection property. This is necessary if you want flexibility in custom sorting. For example, if you sort the DataGridView by multiple columns, you might want to display multiple sorting glyphs or no sorting glyph.

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/column-sort-modes-in-the-windows-forms-datagridview-control?view=netframeworkdesktop-4.8

@Olina-Zhang Based on this documentation, I believe its by design.

Maybe we can add an overload to GridView.Sort which adds an bool parameter to display a glyph? Or add an optional parameter to the existing method? https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.datagridview.sort?view=windowsdesktop-7.0

The code is currently this on line 28739 of DataGridView.Methods in SortInternal()

if (comparer is null)
{
    Debug.Assert(dataGridViewColumn is not null);
    SortedColumn = dataGridViewColumn;
    SortOrder = (direction == ListSortDirection.Ascending) ? SortOrder.Ascending : SortOrder.Descending;
    if (dataGridViewColumn.SortMode == DataGridViewColumnSortMode.Automatic && dataGridViewColumn.HasHeaderCell)
    {
        dataGridViewColumn.HeaderCell.SortGlyphDirection = SortOrder;
    }
}
else
{
    SortedColumn = null;
    SortOrder = SortOrder.None;
}

@merriemcgaw would the team be okay with an API change to enable this, or would it clash with the intent of the DataGridViewColumnSortMode.Programmatic?

elachlan avatar Jan 16 '23 23:01 elachlan

@elachlan I don't know about the team, but I wasted days trying to the Glyph to display before giving up. Something simple would be a welcome change. I will read all the stuff referenced here and see if it helps but it should not be this hard.

paul1956 avatar Jan 17 '23 07:01 paul1956

@elachlan I don't know about the team, but I wasted days trying to the Glyph to display before giving up. Something simple would be a welcome change. I will read all the stuff referenced here and see if it helps but it should not be this hard.

Thanks Paul, I have been going through the back log and this one came up. I think the API change would be simple enough and seems logical.

elachlan avatar Jan 17 '23 07:01 elachlan

@merriemcgaw would the team be okay with an API change to enable this, or would it clash with the intent of the DataGridViewColumnSortMode.Programmatic?

@elachlan I would recommend that we go through the API Review Process to be officially approved. We can update the first comment in this issue with your prepared API representation. @dreddy-work and I could shepherd your API suggestion through the process, but you are also more than welcome to attend the review yourself. It's pretty interesting to participate 😄

merriemcgaw avatar Jan 17 '23 18:01 merriemcgaw

@merriemcgaw thanks, do you want me to raise it against runtime or here in winforms?

elachlan avatar Jan 17 '23 23:01 elachlan

Raise it here and we will make sure it gets through the API review process smoothly. Thanks a ton, this will be very nice to have!

merriemcgaw avatar Jan 19 '23 21:01 merriemcgaw