hello

I have added a checkbox column in my C1TrueDBGrid i want to check all of the checkboxes with single click i have been looking for a solution i found one for DataGridView which is to add a check box in the header of column and check all of the checkbox cells in the checked changed event of the checkbox header... but when i add this code for C1TrueDBGrid it doesn't work it gives a lot of errors one of which is we cannot use C1TrueDBGrid cell as checkbox or Boolean value cannot be compared as string can any one help?

Thanks in advance

If you have added checkbox column as i have suggested you in your previous thread then by adding this code in checkbox_checkedchanged event you will get your desired results hope it will be helpful :)

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                c1TrueDBGrid1.MoveFirst();
                for (int j = 0; j < c1TrueDBGrid1.RowCount; j++)
                {
                    if (checkBox1.CheckState.ToString() == "Checked")
                        c1TrueDBGrid1.Columns[0].Value = true;
                    else 
                      c1TrueDBGrid1.Columns[0].Value = false;

                    c1TrueDBGrid1.MoveNext();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

I am using this code

private void checkBox1_CheckedChanged(object sender, EventArgs e) {
    for (int i = 0; i < c1TrueDBGrid1.RowCount; i++) {
	c1TrueDBGrid1[0, i].Value = ((CheckBox) c1TrueDBGrid1.Controls.Find("checkBox1", true)[0]).Checked;
    }
    c1TrueDBGrid1.EndEdit();
}

abelLazm, you have forgotten to put the 'j' value in the array size inside the For loop and instead you have put '0' itself.

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                c1TrueDBGrid1.MoveFirst();
                for (int j = 0; j < c1TrueDBGrid1.RowCount; j++)
                {
                    if (checkBox1.CheckState.ToString() == "Checked")
                        c1TrueDBGrid1.Columns[j].Value = true;
                    else 
                      c1TrueDBGrid1.Columns[j].Value = false;

                    c1TrueDBGrid1.MoveNext();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

Saikalyankumar i didn't forgot you got it wrong it is

c1TrueDBGrid1.Columns[0].Value = true;

because checkbox is supposed to be the 0th column of c1TrueDBGrid1 so we have to change only its value and not other column's vale hope you understand :)

and bahed121 the code you were using is right for datagridview but not C1TrueDBGrid because the way we access rows and columns is different in both controls

This question has already been answered. Start a new discussion instead.