3

How do I set the column which has the header sort glyph, and its direction, in a .NET 2.0 WinForms ListView?

Bump

The listview is .net is not a managed control, it is a very thin wrapper around the Win32 ListView common control. It's not even a very good wrapper - it doesn't expose all the features of the real listview.

The Win32 listview common control supports drawing itself with themes. One of the themed elements is the header sort arrow. Windows Explorer's listview common control knows how to draw one of its columns with that theme element.

  • does the Win32 listview support specifying which column has what sort order?
  • does the Win32 header control that the listview internally uses support specifying which column has what sort order?
  • does the win32 header control support custom drawing, so I can draw the header sort glyph myself?
  • does the win32 listview control support custom header drawing, so I can draw the header sort glyph myself?
  • does the .NET ListView control support custom header drawing, so I can draw the header sort glyph myself?
4

4 回答 4

3

如果有人需要快速解决方案(它在列标题文本的开头绘制向上/向下箭头):

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);
    }
}

用法:

private void lstOffers_ColumnClick(object sender, ColumnClickEventArgs e)
{
    lstOffers.DrawSortArrow(SortOrder.Descending, e.Column);
}
于 2016-03-31T11:44:18.453 回答
1

I use unicode arrow characters in the title of the column and make the header a linkbutton.

于 2008-09-16T15:04:21.890 回答
1

我使用了一个内置的列表视图。它被称为XPTable ..我正在挖掘我的源代码以找到将根据排序顺序绘制字形的辅助类...这是我在这里使用的代码..

希望这会有所帮助,最好的问候,汤姆。

于 2010-01-15T16:06:57.780 回答
0

本文很有帮助,使用 SendMessage DllImport。

http://www.codeproject.com/Tips/734463/Sort-listview-Columns-and-Set-Sort-Arrow-Icon-on-C

于 2014-11-11T04:19:30.337 回答