How to customize header sort glyph in .NET ListView?

How to set a column with a header sort glyph and its direction in .NET 2.0 WinForms ListView?

Bump

The list - this .net - is not a managed control, it is a very thin shell around the common Win32 ListView control. This is not even a very good wrapper - it does not reveal all the possibilities of a real list.

General Win32 listview control supports drawing themes themselves. One of the thematic elements is the header sort arrow. The Windows Explorer proxy list management tool knows how to draw one of its columns with this theme element.

  • Does Win32 list support support, which column has sort order?
  • Does the Win32 control hold a header containing internal list support that indicates which column has sort order?
  • Does the win32 header control control a custom drawing so that I can draw the header sort glyph myself?
  • Does the listview win32 control support its own header graphic so that I can draw the header header glyph?
  • The ListView.NET control supports custom header drawing, so can I draw the header sort character myself?
+3
source share
4 answers

If someone needs a quick fix (it draws an up / down arrow at the beginning of the column heading text):

ListViewExtensions.cs:

public static class ListViewExtensions
{
    public static void DrawSortArrow(this ListView listView, SortOrder sortOrder, int colIndex)
    {
        string upArrow = "β–²   ";
        string downArrow = "β–Ό   ";

        foreach (ColumnHeader ch in listView.Columns)
        {
            if (ch.Text.Contains(upArrow))
                ch.Text = ch.Text.Replace(upArrow, string.Empty);
            else if (ch.Text.Contains(downArrow))
                ch.Text = ch.Text.Replace(downArrow, string.Empty);
        }

        if (sortOrder == SortOrder.Ascending)
            listView.Columns[colIndex].Text = listView.Columns[colIndex].Text.Insert(0, downArrow);
        else
            listView.Columns[colIndex].Text = listView.Columns[colIndex].Text.Insert(0, upArrow);
    }
}

Application:

private void lstOffers_ColumnClick(object sender, ColumnClickEventArgs e)
{
    lstOffers.DrawSortArrow(SortOrder.Descending, e.Column);
}
+3
source

unicode .

+1

There is a list that I use that has a built in to it. It is called XPTable . I dig my source code to find this helper class that will draw a glyph based on the sort order. This is the code I used here .

Hope this helps, Regards, Tom.

+1
source
0
source

Source: https://habr.com/ru/post/1696968/


All Articles