DataGridView checkbox column - value and functionality

后端 未结 11 1740
一向
一向 2020-11-28 12:17

I\'ve added a checkbox column to a DataGridView in my C# form. The function needs to be dynamic - you select a customer and that brings up all of their items that could be s

11条回答
  •  暖寄归人
    2020-11-28 12:36

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
        ch1 = (DataGridViewCheckBoxCell)dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0];
    
        if (ch1.Value == null)
            ch1.Value=false;
        switch (ch1.Value.ToString())
        {
            case "True":
                ch1.Value = false;
                break;
            case "False":
                ch1.Value = true;
                break;
        }
        MessageBox.Show(ch1.Value.ToString());
    }
    

    best solution to find if the checkbox in the datagridview is checked or not.

提交回复
热议问题