I want to insert a header checkbox in the datagridview. How can I do select all checkbox header? I am trying this codes but I couldn't succeed it.
private void PersonelEkle_Load(object sender, EventArgs e)
{
Point headerCellLocation = this.dataGridView1.GetCellDisplayRectangle(0, -1, true).Location;
DataGridViewCheckBoxColumn CBColumn = new DataGridViewCheckBoxColumn();
CBColumn.Name = "X";
CBColumn.HeaderText = "ColumnHeader";
CBColumn.Width = 30;
CBColumn.FalseValue = "0";
CBColumn.TrueValue = "1";
dataGridView1.Columns.Insert(0, CBColumn);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells[0];
chk.Value = !(chk.Value == null ? false : (bool)chk.Value); //because chk.Value is initialy null
}
}
Amit MohantyPosted Jun 5, 2023, 12:52 PM
Try this:
Mehmet FatihPosted Jun 5, 2023, 3:16 PM
Thnaks a lot Amit Mohanty. It was solved. You are wonderful. I am gratefull to you. Everting works fine.
Amit MohantyPosted Jun 5, 2023, 1:42 PM
The "ambiguous reference" error occurs when there are multiple conflicting references to the same class or type. Declare the CheckBox like this: