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.
Thnx,

I got the same problem in C# and thanks to your comment it got fixed. My class with an overridden ToString() returned nothing too.

Regards,

Samuel

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