public void ShowSortOnHeader(int column, SortOrder order) { IntPtr headersHwnd = NativeMethods.SendMessage(this.Handle, NativeMethods.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); for (int processCols = 0; processCols <= this.Columns.Count; processCols++) { NativeMethods.HDITEM headerInfo = default(NativeMethods.HDITEM); headerInfo.mask = NativeMethods.HDI_FORMAT; NativeMethods.SendMessage(headersHwnd, NativeMethods.HDM_GETITEM, (IntPtr)processCols, ref headerInfo); if (order != SortOrder.None && processCols == column) { switch (order) { case SortOrder.Ascending: headerInfo.fmt = headerInfo.fmt & ~NativeMethods.HDF_SORTDOWN; headerInfo.fmt = headerInfo.fmt | NativeMethods.HDF_SORTUP; break; case SortOrder.Descending: headerInfo.fmt = headerInfo.fmt & ~NativeMethods.HDF_SORTUP; headerInfo.fmt = headerInfo.fmt | NativeMethods.HDF_SORTDOWN; break; } } else { headerInfo.fmt = headerInfo.fmt & ~NativeMethods.HDF_SORTDOWN & ~NativeMethods.HDF_SORTUP; } NativeMethods.SendMessage(headersHwnd, NativeMethods.HDM_SETITEM, (IntPtr)processCols, ref headerInfo); } }
public void ShowSortOnHeader(int column, SortOrder order) { IntPtr headersHwnd = NativeMethods.SendMessage(this.Handle, NativeMethods.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); for (int processCols = 0; processCols <= this.Columns.Count; processCols++) { NativeMethods.HDITEM headerInfo = new NativeMethods.HDITEM(); headerInfo.mask = NativeMethods.HDI_FORMAT; NativeMethods.SendMessage(headersHwnd, NativeMethods.HDM_GETITEM, (IntPtr)processCols, ref headerInfo); if (order != SortOrder.None && processCols == column) { switch (order) { case SortOrder.Ascending: headerInfo.fmt = headerInfo.fmt & ~NativeMethods.HDF_SORTDOWN; headerInfo.fmt = headerInfo.fmt | NativeMethods.HDF_SORTUP; break; case SortOrder.Descending: headerInfo.fmt = headerInfo.fmt & ~NativeMethods.HDF_SORTUP; headerInfo.fmt = headerInfo.fmt | NativeMethods.HDF_SORTDOWN; break; } } else { headerInfo.fmt = headerInfo.fmt & ~NativeMethods.HDF_SORTDOWN & ~NativeMethods.HDF_SORTUP; } NativeMethods.SendMessage(headersHwnd, NativeMethods.HDM_SETITEM, (IntPtr)processCols, ref headerInfo); } }