Ivan Mitev In The Software Trenches

Technology weblog on .NET development and other things that make the world go round

October 22, 2006

Unimaginable, stupid bug

Yesterday I had a crazy debugging session on a simple code that just refused to work. I had a listbox which I wanted to databind to a list of objects. I set its DataSource, but the listbox remained empty. So I began thinking and experimenting:
  1. Maybe the data binding code is somehow wrong? I searched and tried at least four other approaches to databind the list - still empty.
  2. I added the objects to the listbox items collection one by one (no databinding) - still empty.
  3. I added a few random strings to the items collection (the simplest case) - still empty.
Debugging the code revealed that the listbox had the proper items, but somehow they were not displayed. Pure evil! I inspected every reference to the listbox to see if I messed up something without intention. I also looked at all properties related to its visual behaviour. Everything seemed OK.

In desperation I did a little experiment to try to isolate the problem - binding another listbox to another array of object. It worked fine, so I realized that the cause of the problem should be something really stupid. You bet, I was right.

There was another listbox above mine, which I had accidentally added to the form, and it was hiding it completely
.

Those evil listbox was never filled with items, so no wonder it was empty. Spending more than an hour on something like this can really be a pain when you you are racing against a deadline, as it was in this case...