Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 66807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:09:40+00:00 2026-05-10T19:09:40+00:00

How can I display a sort arrow in the header of the sorted column

  • 0

How can I display a sort arrow in the header of the sorted column in a list view which follows the native look of the operating system?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:09:41+00:00Added an answer on May 10, 2026 at 7:09 pm

    You can use the following extension method to set the sort arrow to a particular column:

    [EditorBrowsable(EditorBrowsableState.Never)] public static class ListViewExtensions {     [StructLayout(LayoutKind.Sequential)]     public struct HDITEM     {         public Mask mask;         public int cxy;         [MarshalAs(UnmanagedType.LPTStr)] public string pszText;         public IntPtr hbm;         public int cchTextMax;         public Format fmt;         public IntPtr lParam;         // _WIN32_IE >= 0x0300          public int iImage;         public int iOrder;         // _WIN32_IE >= 0x0500         public uint type;         public IntPtr pvFilter;         // _WIN32_WINNT >= 0x0600         public uint state;          [Flags]         public enum Mask         {             Format = 0x4,       // HDI_FORMAT         };          [Flags]         public enum Format         {             SortDown = 0x200,   // HDF_SORTDOWN             SortUp = 0x400,     // HDF_SORTUP         };     };      public const int LVM_FIRST = 0x1000;     public const int LVM_GETHEADER = LVM_FIRST + 31;      public const int HDM_FIRST = 0x1200;     public const int HDM_GETITEM = HDM_FIRST + 11;     public const int HDM_SETITEM = HDM_FIRST + 12;      [DllImport('user32.dll', CharSet = CharSet.Auto, SetLastError = true)]     public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);      [DllImport('user32.dll', CharSet = CharSet.Auto, SetLastError = true)]     public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);      public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)     {         IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);         for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)         {             var columnPtr = new IntPtr(columnNumber);             var item = new HDITEM                 {                     mask = HDITEM.Mask.Format                 };              if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)             {                 throw new Win32Exception();             }              if (order != SortOrder.None && columnNumber == columnIndex)             {                 switch (order)                 {                     case SortOrder.Ascending:                         item.fmt &= ~HDITEM.Format.SortDown;                         item.fmt |= HDITEM.Format.SortUp;                         break;                     case SortOrder.Descending:                         item.fmt &= ~HDITEM.Format.SortUp;                         item.fmt |= HDITEM.Format.SortDown;                         break;                 }             }             else             {                 item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;             }              if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)             {                 throw new Win32Exception();             }         }     } } 

    Then, you can call the extension method like such:

    myListView.SetSortIcon(0, SortOrder.Ascending); 

    It works by using P/Invoke to:

    • Get the handle to the header control for a list view using the LVM_GETHEADER message.
    • Get the information about a header column using the HDM_GETITEM message.
    • It then modifies the fmt to set / clear the HDF_SORTDOWN and HDF_SORTUP flags on the returned HDITEM structure.
    • Finally it re-sets the information usintg the HDM_SETITEM message.

    This is what it looks like:

    Arrows on a list view column

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i display custom sort direction image in wpf datagrid header? I use
How i can display all applications icons and name which are installed in device
Is there any firefox addon which can display my asp.net page viewstate size.... Any
I want to develop JSF page which can display the swap size if the
I have this code which can display drop down in div tag of html.
I need to create a simple app which can display geometries from Oracle Spatial
I want to display a fullscreen image on which I can run a slide
How can I display some sort of a busy indicator in my WPF application?
I can display a simple Visual Basic inputbox from a PowerShell script like this:
how i can display Name - LastName with ViewBag? <h2> @{ViewBag.Name;} - @{ViewBag.LastName;} </h2>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.