开发者

How to remove icon space after null SmallImageList property of ListView

The problem is, once the SmallImageList is set to imgList1, it never "releases" the icon spacing, even when the SmallImageList is set to null. The item is always indented the same whether there 开发者_开发技巧is an icon or not.

any solution?


This is an unusual thing to do, the .NET ListView wrapper wouldn't handle it. You could try recreating the native Windows control to reset it. Not sure it this will have side-effects, you'd have to try. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox, replacing your original.

using System;
using System.Windows.Forms;

class MyListView : ListView {
    public new ImageList SmallImageList {
        get { return base.SmallImageList; }
        set {
            base.SmallImageList = value;
            if (value == null && base.IsHandleCreated) this.RecreateHandle();
        }
    }
}


Thank you to Hans for the solution. The code below follows his example, but calls the RecreateHandle method using reflection.

this.listView1.SmallImageList = null;
MethodInfo mInfo = this.listView1.GetType().GetMethod(
    "RecreateHandle", BindingFlags.Instance | BindingFlags.NonPublic);
mInfo.Invoke(this.listView1, null);

HTH!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜