智能手机获胜应用程序的组合框加载问题
正在开发智能手机应用程序。这里我有一个组合框,当另一个组合的值发生更改时会加载该组合框。
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";
}
加载此表单时,
(int)cmbTreatmentType.SelectedValue
抛出异常,例如
Cannot unbox '((System.Windows.Forms.ListControl)(this.cmbTreatmentType)).SelectedValue' as a 'int '
假设 cmbTreatmentType 的 DataSource 是 DataTable,语法与上面相同。
但如果您通过调试检查该值,则一切顺利,没有异常。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
组合框
SelectedValue
无法取消装箱为int
。请检查您要取消装箱的值:可能是null
(因为数据源尚未设置)?The combo box
SelectedValue
cannot be unboxed toint
. Please check what value are you trying to unbox: maybenull
(as the data source is not set yet) ?