views:

12

answers:

1

Am working on smartphone application. Here I have a combobox which loads when the value of another combo gets changed.

private void cmbTreatmentType_SelectedIndexChanged(object sender, EventArgs e)
{
     MasterData lData = new MasterData();
     cmbTreatmentCategory.DataSource = lData.GetTreatmentCategories((int)cmbTreatmentType.SelectedValue);     
     cmbTreatmentCategory.DisplayMember = "Description";
     cmbTreatmentCategory.ValueMember = "ID";
}

When this form gets loaded

(int)cmbTreatmentType.SelectedValue

throws exception like

Cannot unbox '((System.Windows.Forms.ListControl)(this.cmbTreatmentType)).SelectedValue' as a 'int'

Provided that the DataSource of cmbTreatmentType is DataTable as syntex same above.

But if you check the value through Debuging it goes well and no exception.

A: 

The combo box SelectedValue cannot be unboxed to int. Please check what value are you trying to unbox: maybe null (as the data source is not set yet) ?

thelost