Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: Drawing onto a Windows Form without freezing it Pin
SimpleData26-Feb-10 5:44
SimpleData26-Feb-10 5:44 
GeneralRe: Drawing onto a Windows Form without freezing it Pin
Saksida Bojan26-Feb-10 7:00
Saksida Bojan26-Feb-10 7:00 
GeneralRe: Drawing onto a Windows Form without freezing it Pin
Luc Pattyn26-Feb-10 6:46
sitebuilderLuc Pattyn26-Feb-10 6:46 
QuestionQuad Tree With images Pin
mallikharjunrao8426-Feb-10 3:17
mallikharjunrao8426-Feb-10 3:17 
AnswerRe: Quad Tree With images PinPopular
RugbyLeague26-Feb-10 3:29
RugbyLeague26-Feb-10 3:29 
GeneralRe: Quad Tree With images Pin
Pete O'Hanlon26-Feb-10 5:15
mvePete O'Hanlon26-Feb-10 5:15 
GeneralRe: Quad Tree With images Pin
Keith Barrow26-Feb-10 5:27
professionalKeith Barrow26-Feb-10 5:27 
QuestionListView Column Sort Arrow Pin
#realJSOP26-Feb-10 3:17
mve#realJSOP26-Feb-10 3:17 
Using DotNet 3.5...

I found the following code on the net (I don't remember exactly where, but I do know it's conglomeration of a couple of different examples). It's a ListView extension method that's responsible for putting a sort direction arrow in the column header. The problem is that it places the arrow above the column header text and centers the arrow in the column. I've made a couple of attempts to try to get the arrow to be laced on the right side of the column, but nothing has worked.

My last attempt was to add the line after the switch(order) statement that adds the HDF_BITMAP_ON_RIGHT flag. Can anyone help?

[EditorBrowsable(EditorBrowsableState.Never)]
public static class ListViewExtensions
{
    [StructLayout(LayoutKind.Sequential)]
    protected struct LVCOLUMN
    {
        public Int32 mask;
        public Int32 cx;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string pszText;
        public IntPtr hbm;
        public Int32 cchTextMax;
        public Int32 fmt;
        public Int32 iSubItem;
        public Int32 iImage;
        public Int32 iOrder;
    }

    const Int32 HDI_WIDTH           = 0x0001;
    const Int32 HDI_HEIGHT          = HDI_WIDTH;
    const Int32 HDI_TEXT            = 0x0002;
    const Int32 HDI_FORMAT          = 0x0004;
    const Int32 HDI_LPARAM          = 0x0008;
    const Int32 HDI_BITMAP          = 0x0010;
    const Int32 HDI_IMAGE           = 0x0020;
    const Int32 HDI_DI_SETITEM      = 0x0040;
    const Int32 HDI_ORDER           = 0x0080;
    const Int32 HDI_FILTER          = 0x0100;

    const Int32 HDF_LEFT            = 0x0000;
    const Int32 HDF_RIGHT           = 0x0001;
    const Int32 HDF_CENTER          = 0x0002;
    const Int32 HDF_JUSTIFYMASK     = 0x0003;
    const Int32 HDF_RTLREADING      = 0x0004;
    const Int32 HDF_OWNERDRAW       = 0x8000;
    const Int32 HDF_STRING          = 0x4000;
    const Int32 HDF_BITMAP          = 0x2000;
    const Int32 HDF_BITMAP_ON_RIGHT = 0x1000;
    const Int32 HDF_IMAGE           = 0x0800;
    const Int32 HDF_SORTUP          = 0x0400;
    const Int32 HDF_SORTDOWN        = 0x0200;
 
    const Int32 LVM_FIRST           = 0x1000;         // List messages
    const Int32 LVM_GETHEADER       = LVM_FIRST + 31;
    const Int32 HDM_FIRST           = 0x1200;         // Header messages
    const Int32 HDM_SETIMAGELIST    = HDM_FIRST + 8;
    const Int32 HDM_GETIMAGELIST    = HDM_FIRST + 9;
    const Int32 HDM_GETITEM         = HDM_FIRST + 11;
    const Int32 HDM_SETITEM         = HDM_FIRST + 12;

    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll", EntryPoint = "SendMessage")]
    private static extern IntPtr SendMessageLVCOLUMN(IntPtr hWnd, Int32 Msg, IntPtr wParam, ref LVCOLUMN lPLVCOLUMN);

    public static void SetSortIcon(this ListView listView, int columnIndex, SortOrder order)
    {
        IntPtr columnHeader = SendMessage(listView.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);

        for (int columnNumber = 0; columnNumber <= listView.Columns.Count - 1; columnNumber++)
        {
            IntPtr columnPtr  = new IntPtr(columnNumber);
            LVCOLUMN lvColumn = new LVCOLUMN();
            lvColumn.mask     = HDI_FORMAT;
            SendMessageLVCOLUMN(columnHeader, HDM_GETITEM, columnPtr, ref lvColumn);
            if (!(order == SortOrder.None) && columnNumber == columnIndex)
            {
                switch (order)
                {
                    case SortOrder.Ascending:
                        lvColumn.fmt &= ~HDF_SORTDOWN;
                        lvColumn.fmt |= HDF_SORTUP;
                        break;
                    case SortOrder.Descending:
                        lvColumn.fmt &= ~HDF_SORTUP;
                        lvColumn.fmt |= HDF_SORTDOWN;
                        break;
                }
                lvColumn.fmt |= (HDF_LEFT | HDF_BITMAP_ON_RIGHT);
            }
            else
            {
                lvColumn.fmt &= ~HDF_SORTDOWN & ~HDF_SORTUP & ~HDF_BITMAP_ON_RIGHT;
            }
            SendMessageLVCOLUMN(columnHeader, HDM_SETITEM, columnPtr, ref lvColumn);
        }
    }
}
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

AnswerTry this Pin
Pete O'Hanlon26-Feb-10 5:39
mvePete O'Hanlon26-Feb-10 5:39 
GeneralRe: Try this Pin
#realJSOP26-Feb-10 9:02
mve#realJSOP26-Feb-10 9:02 
GeneralRe: Try this Pin
Pete O'Hanlon26-Feb-10 9:46
mvePete O'Hanlon26-Feb-10 9:46 
GeneralRe: Try this Pin
#realJSOP27-Feb-10 0:55
mve#realJSOP27-Feb-10 0:55 
GeneralRe: Try this Pin
#realJSOP27-Feb-10 3:58
mve#realJSOP27-Feb-10 3:58 
GeneralRe: Try this Pin
Pete O'Hanlon1-Mar-10 1:12
mvePete O'Hanlon1-Mar-10 1:12 
GeneralRe: Try this Pin
Pete O'Hanlon1-Mar-10 9:34
mvePete O'Hanlon1-Mar-10 9:34 
AnswerRe: ListView Column Sort Arrow Pin
-tusk-22-Jun-11 6:10
-tusk-22-Jun-11 6:10 
GeneralRe: ListView Column Sort Arrow Pin
-tusk-24-Jun-11 2:57
-tusk-24-Jun-11 2:57 
Question2d array in c# Pin
Aljaz11126-Feb-10 3:05
Aljaz11126-Feb-10 3:05 
AnswerRe: 2d array in c# Pin
Pete O'Hanlon26-Feb-10 3:17
mvePete O'Hanlon26-Feb-10 3:17 
GeneralRe: 2d array in c# Pin
Aljaz11126-Feb-10 3:20
Aljaz11126-Feb-10 3:20 
GeneralRe: 2d array in c# [modified] Pin
Dan Mos26-Feb-10 3:26
Dan Mos26-Feb-10 3:26 
GeneralRe: 2d array in c# Pin
harold aptroot26-Feb-10 4:24
harold aptroot26-Feb-10 4:24 
GeneralRe: 2d array in c# Pin
Aljaz11126-Feb-10 6:39
Aljaz11126-Feb-10 6:39 
GeneralRe: 2d array in c# Pin
harold aptroot26-Feb-10 6:46
harold aptroot26-Feb-10 6:46 
GeneralRe: 2d array in c# Pin
Aljaz11126-Feb-10 7:47
Aljaz11126-Feb-10 7:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.