tinyjo: (webdesigner - chez geek)
The problem: I have a list box, into which I am placing objects by looping through the collection and calling Listbox.Items.Add. When I have one object only, it is not displayed in the box and when I try to add another item I get a System.OutOfMemoryException with the message that there are too many items in the list box.

The solution: It turned out, after much investigation that this problem was being caused by the fact that I was calling BeginUpdate before adding the single item to the box and EndUpdate afterwards. These are intended to avoid lots of re-draws when adding lots of items to a list box but apparently if you call them when only adding one thing, something somewhere breaks. Even adding 2 things, you're OK, but one thing, no. So all I did was add conditional code to not call them if I had one item to put in the listbox and bingo.

Date: March 30th, 2005 03:02 pm (UTC)From: [identity profile] celestialweasel.livejournal.com
But do you think Google will ever scan your LJ :-)

Date: October 17th, 2005 04:37 pm (UTC)From: (Anonymous)
Hi,

Well, I found your tip and it was exactly what I was looking for! Or so I thought, your solution doesn't work for my code but I'm still glad to have found someone else that has had this problem. I've Googled and searched MSDN but nothing. Your post is the only thing I've found so far...

So thanks for the tip!
//Girlie

"Too many items in List Box" error - caused by ToString override returning nothing

Date: December 21st, 2005 04:38 pm (UTC)From: (Anonymous)
I had this "Too many items in List Box" error when I was adding a set of classes to a checked list box items collection one at a time in a for loop.

The classes I was adding had an override for the ToString property, overridden via a delegate.

One instance of the class returned nothing for the overridden ToString property.

I loaded up the checked list box during form load - no error.

The checked list box was on the second tab page of a tab control & when I clicked on that page hey presto, the error message was displayed ( ie when the overridden ToString sub returned nothing to the checked list box, when the checked list box was trying to display the text for each item in the list, which it does by calling the object's ToString method by default)

This list is still the only resource on the subject, and I found it via Google ;-)

Regards,
Graeme
ps VB.NET 2003, .NET Framework 1.1 SP1, XP PRo

Hello

Date: August 16th, 2008 10:03 am (UTC)From: (Anonymous)
I'm new here, just wanted to say hello and introduce myself.

Profile

tinyjo: (Default)
Emptied of expectation. Relax.

June 2020

S M T W T F S
 1 23456
78910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Expand Cut Tags

No cut tags
Page generated January 23rd, 2026 01:50 pm
Powered by Dreamwidth Studios

Style Credit