tags:

views:

86

answers:

1

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?

+1  A: 

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.

slugster
I tried the method what you have told ,But then also that exception is coming some times
We need to know *where* the exception is happening - what line? What are the surrounding lines of code? This should all be easy to determine if you are using a debugger.
slugster