/// <summary> Sets the sort arrow to a particular column in the list view. </summary> /// <param name="ColumnToShowArrow"> Index of the column where the sort arrow will be displayed </param> public void SetSortArrow( int ColumnToShowArrow, bool bSortModeAscending ) { if( ListViewHeader == null ) { return; } IntPtr ColumnHeader = ListViewHeader.Handle; for( int ColumnIndex = 0; ColumnIndex < Columns.Count; ColumnIndex++ ) { IntPtr ColumnPtr = new IntPtr( ColumnIndex ); ListViewWin32.HDITEM ListViewColumn = new ListViewWin32.HDITEM(); ListViewColumn.mask = ListViewWin32.HDI_FORMAT; ListViewWin32.SendMessageHeaderItem( ColumnHeader, ListViewWin32.HDM_GETITEM, ColumnPtr, ref ListViewColumn ); bool bIsSortArrowDown = ( ( ListViewColumn.fmt & ListViewWin32.HDF_SORTDOWN ) == ListViewWin32.HDF_SORTDOWN ); bool bIsSortArrowUp = ( ( ListViewColumn.fmt & ListViewWin32.HDF_SORTUP ) == ListViewWin32.HDF_SORTUP ); // Change the sort arrow to opposite direction. if( ColumnToShowArrow == ColumnIndex ) { if( bSortModeAscending ) { ListViewColumn.fmt &= ~ListViewWin32.HDF_SORTDOWN; ListViewColumn.fmt |= ListViewWin32.HDF_SORTUP; } else { ListViewColumn.fmt &= ~ListViewWin32.HDF_SORTUP; ListViewColumn.fmt |= ListViewWin32.HDF_SORTDOWN; } } else { ListViewColumn.fmt &= ~ListViewWin32.HDF_SORTDOWN & ~ListViewWin32.HDF_SORTUP; } ListViewWin32.SendMessageHeaderItem( ColumnHeader, ListViewWin32.HDM_SETITEM, ColumnPtr, ref ListViewColumn ); } }
/// <summary> Sets the sort arrow to a particular column in the list view. </summary> /// <param name="ColumnToShowArrow"> Index of the column where the sort arrow will be displayed </param> public void SetSortArrow(int ColumnToShowArrow, bool bSortModeAscending) { if (ListViewHeader == null) { return; } IntPtr ColumnHeader = ListViewHeader.Handle; for (int ColumnIndex = 0; ColumnIndex < Columns.Count; ColumnIndex++) { IntPtr ColumnPtr = new IntPtr(ColumnIndex); ListViewWin32.HDITEM ListViewColumn = new ListViewWin32.HDITEM(); ListViewColumn.mask = ListViewWin32.HDI_FORMAT; ListViewWin32.SendMessageHeaderItem(ColumnHeader, ListViewWin32.HDM_GETITEM, ColumnPtr, ref ListViewColumn); bool bIsSortArrowDown = ((ListViewColumn.fmt & ListViewWin32.HDF_SORTDOWN) == ListViewWin32.HDF_SORTDOWN); bool bIsSortArrowUp = ((ListViewColumn.fmt & ListViewWin32.HDF_SORTUP) == ListViewWin32.HDF_SORTUP); // Change the sort arrow to opposite direction. if (ColumnToShowArrow == ColumnIndex) { if (bSortModeAscending) { ListViewColumn.fmt &= ~ListViewWin32.HDF_SORTDOWN; ListViewColumn.fmt |= ListViewWin32.HDF_SORTUP; } else { ListViewColumn.fmt &= ~ListViewWin32.HDF_SORTUP; ListViewColumn.fmt |= ListViewWin32.HDF_SORTDOWN; } } else { ListViewColumn.fmt &= ~ListViewWin32.HDF_SORTDOWN & ~ListViewWin32.HDF_SORTUP; } ListViewWin32.SendMessageHeaderItem(ColumnHeader, ListViewWin32.HDM_SETITEM, ColumnPtr, ref ListViewColumn); } }