Smartphone win Application 's combobox load problem
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
t开发者_如何学编程hrows 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.
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) ?
精彩评论