Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

Glitchy ListView control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul E Collins - 02 Jan 2007 18:48 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.