Beispiel #1
0
        public static void SetSortIcon( this ListView lv, int columnIndex, SortOrder order )
        {
            IntPtr columnHeader = SendMessage ( lv.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero );

            for ( int columnNumber = 0; columnNumber <= lv.Columns.Count - 1; columnNumber++ ) {
                IntPtr columnPtr = new IntPtr ( columnNumber );
                LVCOLUMN lvColumn = new LVCOLUMN ( );
                lvColumn.mask = HDI_FORMAT;
                SendMessage ( columnHeader, HDM_GETITEM, columnPtr, ref lvColumn );

                if ( !( order == System.Windows.Forms.SortOrder.None ) && columnNumber == columnIndex ) {
                    switch ( order ) {
                        case System.Windows.Forms.SortOrder.Ascending:
                            lvColumn.fmt &= ~HDF_SORTDOWN;
                            lvColumn.fmt |= HDF_SORTUP;
                            break;
                        case System.Windows.Forms.SortOrder.Descending:
                            lvColumn.fmt &= ~HDF_SORTUP;
                            lvColumn.fmt |= HDF_SORTDOWN;
                            break;
                    }
                } else {
                    lvColumn.fmt &= ~HDF_SORTDOWN & ~HDF_SORTUP;
                }

                SendMessage ( columnHeader, HDM_SETITEM, columnPtr, ref lvColumn );
            }
        }
Beispiel #2
0
 internal static extern IntPtr SendMessage( IntPtr hwnd, Int32 msg, IntPtr wParam, ref LVCOLUMN lParam );
 private static extern IntPtr SendMessageLVCOLUMN(IntPtr hWnd, Int32 Msg, IntPtr wParam, ref LVCOLUMN lPLVCOLUMN);