user285008
user285008

Reputation: 73

How to Solve the inner Exception i.e. index out of range

I am storing items into a combo box which had been retrieved from the database in the following manner:

cmbCustomerName.DataSource = null;
cmbCustomerName.DataSource = result;
cmbCustomerName.ValueMember = "CustomerID";
cmbCustomerName.DisplayMember = "CustomerName";
cmbCustomerName.Text = null;

Its working, but often showing the inner exception "Index Out of Range". Why does this error occur?

Upvotes: 0

Views: 856

Answers (1)

slugster
slugster

Reputation: 49974

You have given us next to no code, can you be sure that the exception is happening in that bit of code you posted?

I'm assuming that you are wanting to have the combo unselected after you set its DataSource which is why you are setting the Text to null, if i am wrong then please say so.

To unselect everything in the combo, set the SelectedIndex to -1. There is also no need to set the DataSource to null before setting it to something else.

Upvotes: 1

Related Questions