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.