Beginner level VB.NET question

  • Thread starter Thread starter OregonMike
  • Start date Start date
The exception is thrown on setting the SelectedIndex = 1.

Brian Gideon said:
This code will throw an ArgumentNullException:

comboBox1.Items.Add("Fred");
comboBox1.Items.Add("Barney");
comboBox1.Items.Add("Wilma");
comboBox1.Items[1] = null;
comboBox1.SelectedIndex = 1;

I would break before you set the selectedindex and see what object is at
items [1].

Well, that's not the same exception the OP was getting, but it's
interesting nonetheless. What line generated the exception? Last?
Second to last?
 
Mike,

Your combobox is of course never null/nothing if you have created it in the
designer. Then it is a Global created control.

However your index can of course be -1. This is often at the moment the
combobox is initializing.

You can as well test the count of the items. However that does nothing if
you are using the datasource, than you have to see what is the length/count
of your datasource items.

Cor
 
At this point I would advise trying to replicate in as small a piece of code
as possible, a complete working example of this going wrong.

I would start with the smallest piece of your solution that will compile
independantly and start elliminating pieces of it until you have something
small you can mail one of us.

You could put it up for general download if you like or I would be happy
to take a look at such an example.
 
Maybe I've missed something.... Didn't you say that you access the object
*after* it has been disposed? This wouldn't work and explain everything.


Armin
 
Back
Top