【问题标题】:Datagridview Checkbox doesn't count as checked before leaving itDatagridview Checkbox 在离开前不算作检查
【发布时间】:2014-07-30 12:38:18
【问题描述】:

我有 Datagridview,其中 4 列用于复选框和 5 行(如复选框矩阵)。当用户选中他想要的复选框并按下“保存”按钮时,除非用户转到任何其他单元格,否则最后编辑的复选框不会更改(不更改任何内容,只需从单元格中移动)。 我不知道如何解决这个问题。

for (int i = 0; i < dgv_permissions.Rows.Count; i++)
{
    paramList.Clear();
    paramList.Add("uGrpPermissionModule", dgv_permissions.Rows[i].Cells[0].Value.ToString());                    
    paramList.Add("uGrpRead", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[1].Value.ToString()));
    paramList.Add("uGrpNew", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[2].Value.ToString()));
    paramList.Add("uGrpUpdate", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[3].Value.ToString()));
    paramList.Add("uGrpDelete", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[4].Value.ToString()));
    paramList.Add("uGrpReports", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[5].Value.ToString()));
    try
    {
        retval = DBFucntions.doWriteCommand(sqlStr, paramList);                 
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error");
    }
}

【问题讨论】:

标签: c# winforms checkbox datagridview


【解决方案1】:

我认为这与复选框列没有真正合适的编辑控件有关。每当我遇到这个问题时,我都会对DataGridView 上的CurrentCellDirtyStateChanged 事件使用以下事件处理程序:

private void DataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
    if (this.mDataGridView.IsCurrentCellDirty &&
        (this.mDataGridView.CurrentCell.OwningColumn == /* check box column */))
    {
        this.mDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多