【问题标题】:DataGridViewCheckBoxColumn: how to update bound DataSource on property changed instead of on validationDataGridViewCheckBoxColumn:如何在属性更改而不是验证时更新绑定的 DataSource
【发布时间】:2011-06-24 13:10:25
【问题描述】:

我已经绑定了一个 BindingList 作为 DataGridView 的数据源; TSource 属性之一绑定到 DataGridViewCheckBoxColumn,但数据源不是在单击复选框时更新,而是在复选框本身失去焦点时更新。

我知道当 DataSourceUpdateMode 为“OnValidation”而不是“OnPropertyChanged”时,标准 WindowsForms 绑定上会发生类似的情况,但是如何使用 DataGridViewCheckBoxColumn 获得相同的结果?

列定义如下:

            DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
            column.DataPropertyName = "MyProperty";
            column.HeaderText = "Title";

            dataGridView.Columns.Add(column);

【问题讨论】:

    标签: winforms binding datagridview datagridviewcolumn


    【解决方案1】:

    您可以通过处理DataGridViewCurrentCellDirtyStateChanged 事件来做到这一点。

    void dataGridView1_CurrentCellDirtyStateChanged(object sender,EventArgs e)
    {
        if (dataGridView1.IsCurrentCellDirty)
        {
            dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-24
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      相关资源
      最近更新 更多