【问题标题】:Bound DataGridViewCheckBoxColumn not updating binding source绑定的 DataGridViewCheckBoxColumn 不更新绑定源
【发布时间】:2010-01-12 09:11:09
【问题描述】:

我已将 DataGridView 绑定到绑定源,其中数据源作为活动记录模型列表:

    BindingSource bs = new BindingSource();
    bs.DataSource = _user.Addresses;

Address 有名为 Actual 的 bool 属性,而我的 DataGridView 有 CheckBoxColumn:

    DataGridViewCheckBoxColumn c = new DataGridViewCheckBoxColumn(false);
    c.Name = "actualColumn";
    c.HeaderText = "Aktualny";
    c.DataPropertyName = "Actual";
    c.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
    addressesDataGridView.Columns.Add(c);

数据库中的数据显示正确。

当我单击选中的复选框单元格并取消选中它然后转到保存按钮时,我的绑定源中的属性 Actual 未被取消选中。

当我单击选中的复选框单元格并取消选中它并更改行选择然后单击保存时,按钮更改在 bindingsource 中可见。

此问题是否存在解决方法?

【问题讨论】:

    标签: c# datagridview


    【解决方案1】:

    问题是数据网格没有更新底层数据源。

    您可以尝试调用 BindingSource.EndEdit 作为保存功能中的第一件事。

    您还可以尝试在绑定到控件的 CurrencyManager 上调用 EndCurrentEdit。要访问它,您可以:

    myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];

    【讨论】:

    • 您的建议都没有奏效,但您启发了我(为此 +1 :),谢谢)并且在保存功能之上的以下位置有效:addressesDataGridView.EndEdit()
    猜你喜欢
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 2010-09-19
    相关资源
    最近更新 更多