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?
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.
精彩评论