【问题标题】:c# Is there an event for datagridview's checkedboxc#是否有datagridview复选框的事件
【发布时间】:2012-06-18 21:03:09
【问题描述】:

我想知道每次有人检查 datagridview 的复选框时是否有一个事件。

我的目标是计算检查了多少行,但我希望每次用户检查时都刷新计数,这就是为什么我想知道您所做的每次检查是否都有一个事件。 (就像在普通复选框中一样,checkBox_CheckedChanged)

谢谢

【问题讨论】:

  • 需要在gridview命令事件中调用datagridview的子元素。

标签: c# events datagridview datagridviewcheckboxcell


【解决方案1】:

没有(据我所知),但您可以使用这个简单的解决方法:

private void dgAreas_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    IsChecked = (bool)dgAreas[e.ColumnIndex, e.RowIndex].EditedFormattedValue
    ...

}

您必须监听 CellContentClick 事件。

【讨论】:

    【解决方案2】:

    试试这个:

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {
        //Closing current edited cell (for prevent problems)
        this.dataGridView1.EndEdit();
        //Retrive the datasource from the gridView in a DataTable (in this case, i use a DataSource with Visual Studio Wizard
        DataTable source = ((DataSet)((BindingSource)this.dataGridView1.DataSource).DataSource).Tables[0];
        //The magic code line ("IdCierre is my checkeable field" in the grid). I use Linq
        this.label_contador.Text = source.AsEnumerable().Where(x => x.Field<bool>("IdCierre") == true).Count().ToString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      相关资源
      最近更新 更多