我知道这是重复的问题。我尝试在重复问题中找到解决方案,但我失败了。
情况是我有 2 个组合框(Telerik Winforms),称为 ComboBranch 和 ComboPanel。当用户在 ComboBranch 中选择某个值时,ComboPanel 将显示不同的值。
所以这是代码
private void tbDropBranch_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
dataPanel();
}
void dataPanel()
{
DataTable dtPanel = dataBinding._valuePanel(Convert.ToInt32(tbDropBranch.SelectedValue.ToString())); // Error in here
tbDropPanel.DataSource = new BindingSource(dtPanel, null);
tbDropPanel.DisplayMember = "panelName";
tbDropPanel.ValueMember = "panelID";
}
更新
如果我做 Event tbDropBranch_Leave 它的工作。但是为什么我在使用 tbDropBranch_SelectedIndexChanged 时出现错误?
private void tbDropBranch_Leave(object sender, EventArgs e)
{
dataPanel();
}
解决方案
我只是这样做:
void getIdBranch()
{
if ("System.Data.DataRowView" == tbDropBranch.SelectedValue.ToString())
{
return;
}
else
{
DataTable dtPanel = dataBinding._valuePanel(Convert.ToInt32(tbDropBranch.SelectedValue.ToString()));
tbDropPanel.DataSource = new BindingSource(dtPanel, null);
tbDropPanel.DisplayMember = "panelName";
tbDropPanel.ValueMember = "panelID";
}
}
感谢那些帮助过的人.. :)