DatagridView Checkbox Checked?

前端 未结 2 1705
夕颜
夕颜 2021-01-24 10:35

i have a check box in a datagridview windows form and have a event handler cell_Click on cell click i check the datagridview column for a check box it shows true if the cell is

2条回答
  •  情书的邮戳
    2021-01-24 11:06

    If I understand you correctly you are saying the checkbox value does not align with the underlying data?

    This may well be because the data has been updated and is 'dirty', e.g. it hasn't been committed to the datasource yet. If you add an event handler like this:

    private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
    {
       if (dataGridView1.CurrentCell is System.Windows.Forms.DataGridViewCheckBoxCell)
       {
          dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
       }
    }
    

    Then that should update the datasource and you'll have the correct checkbox state when you query the cell.

提交回复
热议问题