我InvalidCastException
在以下代码的运行时得到一个“”:
我的 C# WinForm 代码包含一个使用以下代码从数据库填充的组合框:
public void PopulateCompetitionFormatDd()
{
var _competitionFormat = new CompetitionFormatBL();
cbCompetitionFormat.DataSource = _competitionFormat.GetByAllCompetitionFormats();
cbCompetitionFormat.ValueMember = "CompetitionFormatId";
cbCompetitionFormat.DisplayMember = "CompetitionFormatType";
}
( ) 是数字列表,( ValueMember
)是文本。当我在运行时更改此组合框中的项目时,我收到错误“ ”。CompetitionFormatId
DisplayMember
CompetitionFormatType
string
InvalidCastException
private void cbCompetitionFormat_SelectedIndexChanged(object sender, EventArgs e)
{
int competitionFormat = 1;
competitionFormat = (int)cbCompetitionFormat.SelectedValue;
}
任何想法我做错了什么以及如何解决它?