I'm having trouble with the ListView control, which seems to size and
position its child items incorrectly under certain circumstances.
Specifically, when I recreate its ImageList, using a dynamically
created set of images (from pixel data in memory), items are actually
overlapping each other so that their text becomes unreadable.
I can't reproduce the overlap in a simple test project, but I did come
up with the following code (requiring a form with a button on it).
Click the button twice: it does the same thing each time, but the
items in the ListView get formatted differently the second time. Does
anyone understand the quirky rules behind this thing? I just want a
normal SmallIcons view where the text looks right, but my application
needs to do it dynamically.
private ListView lvw = null;
private void Form1_Load(object sender, System.EventArgs e)
{
lvw = new ListView();
this.Controls.Add(lvw);
lvw.Size = new Size(250, 100);
}
private void button1_Click(object sender, System.EventArgs e)
{
ImageList iml = new ImageList();
iml.ImageSize = new Size(16, 16);
lvw.Items.Clear();
lvw.SmallImageList = iml;
lvw.View = View.SmallIcon;
for (int i = 0; i < 10; i++)
{
lvw.Items.Add("Some text");
}
}
Jared - 03 Jan 2007 02:02 GMT
try clearing items before you nuke imagelist
Paul E Collins - 03 Jan 2007 11:16 GMT
> try clearing items before you nuke imagelist
That doesn't make my sample behave any differently.
However, I've now found a slightly dodgy workaround, which is to
change the view mode to large icons and then back to small icons
(which, unlike Refresh, recreates the layout) after the final item has
been added:
lvw.View = View.LargeIcon;
lvw.View = View.SmallIcon;
Eq.