How to know a specific checkbox inside datagridview is checked or not?

橙三吉。 提交于 2019-11-28 13:01:45
 private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
    {
        if (dataGridView1.IsCurrentCellDirty)
        {
            dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
        }
    }

    private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        if (((e.ColumnIndex) == 1) && ((bool)dataGridView1.Rows[e.RowIndex].Cells[1].Value))
        {
            MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());

        }
    }

these below links helped me to understand the concept of cellvalue_changed and cell_content_click.. http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx

and by the help of these links i finally got the solution to my problem

it is as simple as this

//replace the row number and column name with your own 
if ((bool)dataGridView1.Rows[0].Cells["Column1"].Value)
 {
       //do your work
 }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex > -1 && e.ColumnIndex > -1)
    label1.Text = dataGridView1.Rows[e.RowIndex].Cells["Col1"].Value.ToString();
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == *someIndex*)
    {
        DataGridViewCheckBoxCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;
        if (cell != null)
        {
            if (cell.EditingCellValueChanged)
            {
                //CheckBox has been clicked
            }

            //here how to get the checkBoxCell value
            var cellChecked = cell.EditingCellFormattedValue;
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!