【问题标题】:winform: binding problem with DropDownListwinform:与 DropDownList 的绑定问题
【发布时间】:2010-12-01 08:00:17
【问题描述】:

我在 access 数据库文件中有一个表。我想在 DataGridView 中显示该表,我有一个绑定到该表的绑定源。然后 DataGridView 绑定到 bindingsource。我还有其他控件(文本框、组合框)通过相同的绑定源绑定到表的“dataMember”。一切正常。但是当我将组合框的“DropDownStyle”从“DropDown”更改为“DropDownList”时。绑定坏了。当我在 datagridview 中选择不同的行时,组合框中的数据不会更改。但是,当我更改组合框中的数据时,DataGridView 中单元格中的数据发生了变化。有人有想法吗?非常感谢!

The following is my code: 

combobox1.Items.AddRange( new Object[]{
"Monday",
"Tuesday",
.....
.....
"Sunday"
});


bindingsource1.DataSource = dt; // dt is a instance of DataTable
combobox1.DataBindings.Add("Text", bindingsource1,"Day");

【问题讨论】:

  • 我认为您所描述的行为是“设计使然”。

标签: winforms


【解决方案1】:
combobox1.DataBindings.Add("SelectedValue", bindingsource1,"Day");

[编辑]

添加这个:

comboBox1.DisplayMember = "Day";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 2012-07-23
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    相关资源
    最近更新 更多