使用winform数据绑定单独控制

时间:2014-04-10 09:01:18

标签: c# winforms combobox

目前我有两个组合框,我使用数据绑定将组合框绑定到我拥有的对象。问题是组合框绑定在一起,所以如果我更改组合框A,组合框B将随组合框A而改变。

cboHomeTeam.ValueMember = cboHomeTeam.ValueMember;
cboHomeTeam.DisplayMember = "Name";
cboHomeTeam.DataSource = teams;

cboAwayTeam.ValueMember = cboAwayTeam.ValueMember;
cboAwayTeam.DisplayMember = "Name";
cboAwayTeam.DataSource = teams;

如何让每个组合框唯一但仍然绑定到某个对象?

1 个答案:

答案 0 :(得分:0)

处理这种情况的一种简单方法是完全满足您的需求:"当其他组合更改时更新一个组合框"

cboHomeTeam.SelectedIndexChanged += ( s, e ) => cboAwayTeam.SelectedIndex = cboHomeTeam.SelectedIndex;
cboAwayTeam.SelectedIndexChanged += ( s, e ) => cboHomeTeam.SelectedIndex = cboAwayTeam.SelectedIndex;