Вопрос

I know that there are available Properties for ListView to change the common styles but I just want to test this. That is for example the View = View.LargeIcon applies the style LVS_ICON = 0 to the ListView or GridLines = true applies the style LVS_EX_GRIDLINES = 1 to the ListView. I would like to test with CreateParams. I think using GetWindowLong and SetWindowLong Win32 functions would be OK, but for convenience, as far as I know, CreateParams can change the style of a control. But this time with a ListView, I can't make it work, it has no effect at all, I wonder if ListView is a special case?. Here is my code:

public class CustomListView : ListView {        
    protected override CreateParams CreateParams {
      get {
       CreateParams cp = base.CreateParams;
       cp.Style |= 3; //Apply LVS_LIST (View as List)
       return cp;
      }
    }
}

Only LVS_EX_GRIDLINES = 1 makes some effect but the effect is not Grid lines are drawn on the ListView but the Border becomes thicker and looks like 3D-border. That's strange, most of other applies have not effect at all.

Could you explain it or at least give me some example which works? Again please don't give me any solution or code which uses GetWindowLong and SetWindowLong, just use CreateParams.

Thanks!

Это было полезно?

Решение

If it helps to explain how this works, this is handled internally by the ListView.UpdateExtendedStyles function, which gets called when one of the properties relating to an extended style is set.

Quoting from the relevant section on MSDN

msdn

Reflector disassembles the function as follows

protected void UpdateExtendedStyles()
{
    if (base.IsHandleCreated)
    {
        int lparam = 0;
        int wparam = 0x10cfd;
        switch (this.activation)
        {
            case ItemActivation.OneClick:
                lparam |= 0x40;
                break;

            case ItemActivation.TwoClick:
                lparam |= 0x80;
                break;
        }
        if (this.AllowColumnReorder)
        {
            lparam |= 0x10;
        }
        if (this.CheckBoxes)
        {
            lparam |= 4;
        }
        if (this.DoubleBuffered)
        {
            lparam |= 0x10000;
        }
        if (this.FullRowSelect)
        {
            lparam |= 0x20;
        }
        if (this.GridLines)
        {
            lparam |= 1;
        }
        if (this.HoverSelection)
        {
            lparam |= 8;
        }
        if (this.HotTracking)
        {
            lparam |= 0x800;
        }
        if (this.ShowItemToolTips)
        {
            lparam |= 0x400;
        }
        base.SendMessage(0x1036, wparam, lparam);
        base.Invalidate();
    }
}

EDIT

The reason you can't use CreateParams is because it's not relevant for a ListView see MSDN here - excerpt copied below

msdn

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top