Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ListView Items disappear on resize

Posted on 2008-06-10
8
Medium Priority
?
2,451 Views
Last Modified: 2011-08-18
I wonder if anyone has run across this.  I have a ListView in a form inside a splitter panel.  It is anchored on all sides of the panel., as is the splitter control on all sides of the form.  So if I have several items in the listview and begin to remove some rows (I have a button that just removes any selected items) and resize the form (thereby resizing the listview), at some point all the items in the list view will disappear.  If I click on them or select them they will reappear individually.  It's as if the text somehow got changed to white-on-white, but clicking on them brings them back to normal.

It gets worse.  When this happens, there is some blank space at the top, between the border and the first item, about the height of two rows but it's just empty space, not rows..  In all of this I have not added any items other than my initial ones.  I do have one callback on the resize for the control, where I adjust the column widths but that's all.  I can get it to reproduce by using the delete and resize, but others can do it with only using the delete, and sometimes it manifests by making all the rows after the deleted one disappear until they are clicked on.

This may be too vague, I'm trying to see if I can isolate what I need to do to cause it but so far I can't. It is really puzzling to me.  My searches haven't pulled anything up.  I'm using Visual Studio 9.0.21022.8 with C#, it happens on both Vista and XP SP2.

Thanks
0
Comment
Question by:developerius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:gbarcalow
ID: 21754810
Maybe some code would help. My initial though is that somewhere you are calling SuspendLayout() and not calling ResumeLayout().

Is this a listview or a custom control that inherits from listview?
0
 
LVL 3

Expert Comment

by:aphillips
ID: 21756633
If you are overriding OnResize you must remember to call the base class OnResize otherwise no resize events will be sent.
0
 

Author Comment

by:developerius
ID: 21756638
These are the three events that I subscribe to, the delete code called from a button click outside the ListView, the resize, and a selected index change to enable the buttons.  The list is a list of search terms.

This is a regular ListView, always in Details view mode.  I'm not doing anything with the layout, but certainly something like that is going on as I resize and delete.

Hope this helps, thanks
D
private void deleteSelectedSearchItems() {
  if (this.searchListLV.SelectedItems != null) {
    List<ListViewItem> tokill = new List<ListViewItem>();
    foreach (ListViewItem lvi in this.searchListLV.SelectedItems) {
      tokill.Add(lvi);
      //... stuff using the tag ...
    }
    foreach (ListViewItem lvi in tokill) {
      this.searchListLV.Items.Remove(lvi);
    }
  }
}
 
void searchListLV_ClientSizeChanged(object sender, EventArgs e) {
  int w = searchListLV.ClientSize.Width;
  searchListLV.Columns[0].Width = (int)(w * .38);
  searchListLV.Columns[1].Width = Utils.max((int)(w * .1), 70);
  searchListLV.Columns[2].Width = w - searchListLV.Columns[0].Width - searchListLV.Columns[1].Width;
}
 
void searchListLV_SelectedIndexChanged(object sender, EventArgs e) {
  this.saveSearchBtn.Enabled = (searchListLV.Items.Count > 0);
  deleteSearchItemBtn.Enabled = (searchListLV.SelectedItems.Count > 0);
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
gbarcalow earned 2000 total points
ID: 21761163
Maybe a simple solution is to call
searchListLV.Refresh() or searchListLV.Invalidate() in the listview's refresh event to force it to redraw itself.

On a side note:
Setting the width of a column to -2 will automatically size it to the text.
0
 

Author Comment

by:developerius
ID: 21762300
Thanks, qbar.  I tried putting in the invalidate() in the delete event as well as the resize, and so far I haven't been able to reproduce on my machine.  I will know for sure tonight when someone will bring me a vm that will reproduce the problem with no resize, and I'll try this version on it.

I tried using the -2, and i really like the results, but on a resize event that doesn't really work because it seems to keep repainting for a while after I resize - I'm sure it's because of the many resize events that it gets during what is to the user a single resizing event.  I wish there was a "finishedResize" event that I could listen to.  It does give me some options I can use when adding or removing, though.

I also protected against the possibility of using negative numbers in the widths, maybe in some circumstances I was running into that.

Thanks again, I'll post the results tomorrow.
0
 
LVL 3

Expert Comment

by:gbarcalow
ID: 21763282
Just though you might also be able to use this:

"How to detect when a form has FINISHED resizing"
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21633442.html
0
 

Author Comment

by:developerius
ID: 21763588
Wow, much smoother, thanks.
0
 

Author Closing Comment

by:developerius
ID: 31465902
I don't know which of the suggestions did it, but it seems to be clearly fixed now.  I saw it happen easily on the VM and replacing with those fixes made it completely go away.

Thanks a lot, I am able to go on vacation now in peace!
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question