How to remove icon space after null SmallImageList property of ListView

The problem is that if the SmallImageList parameter is set to imgList1, this will never "free" the interval between the icons, even if the SmallImageList parameter is set to null. An element always indents the same whether there is an icon or not.

any solution?

+3
source share
2 answers

This is an unusual thing, but the .NET ListView wrapper won't handle it. You can try to recreate your own Windows control before reset. Not sure if this will have side effects, you will have to try it. Add a new class to your project and paste the code shown below. Compilation. Drop the new control on top of the toolbar, replacing the 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();
        }
    }
}
+4
source

Thanks to Hans for the solution. The following code 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);

NTN!

0
source

Source: https://habr.com/ru/post/1753344/


All Articles