绑定DataGridViewCheckBoxColumn不更新绑定源 [英] Bound DataGridViewCheckBoxColumn not updating binding source

查看:97
本文介绍了绑定DataGridViewCheckBoxColumn不更新绑定源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将DataGridView绑定到一个绑定源与数据源作为活动记录模型的列表:

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

地址具有名为Actual的bool属性,我的DataGridView具有CheckBoxColumn:

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

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



当我点击选中的复选框并取消选中它,然后转到保存按钮,属性在我的绑定源中实际不会被取消选中。



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



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

解决方案

问题是datagrid没有更新基础数据源。



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



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


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



I have DataGridView bound to a bindingsource with datasource as a list of active record models:

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

Address has bool property named Actual, and my DataGridView has CheckBoxColumn:

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

Data from database is displayed properly.

When I click on checked checkbox cell and uncheck it and then go to save button, property Actual in my bindingsource isn't unchecked.

When I click on checked checkbox cell and uncheck it and change row selection and then click save, button changes are visible in bindingsource.

Does a workaround exist for this issue?

解决方案

The problem is that the datagrid is not updating the underlying datasource.

You could try calling BindingSource.EndEdit as the first thing in the Save functionality.

You could also try to call EndCurrentEdit on the CurrencyManager that is bound to the control. To access it you do:

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

这篇关于绑定DataGridViewCheckBoxColumn不更新绑定源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆