Hi all,
I created a CheckBoxColumn in my DataGridView control as per below code:
DataGridViewCheckBoxColumn checkBoxCol = new DataGridViewCheckBoxColumn(); clsDataGridViewCheckBoxHeaderCell checkBoxHeader = new clsDataGridViewCheckBoxHeaderCell(); checkBoxCol.HeaderCell = checkBoxHeader; checkBoxCol.Width = 50; dgv_1.Columns.Add(checkBoxCol); checkBoxHeader.OnCheckBoxClicked += new CheckBoxClickedHandler(CheckBoxHeader_OnCheckBoxClicked);
And I am able to check and uncheck all the checkboxcells in my DataGridView by below code:
private void CheckBoxHeader_OnCheckBoxClicked(bool isCheckedAll)
{
try
{
dgv_1.EndEdit();
foreach (DataGridViewRow row in dgv_1.Rows)
{
row.Cells[0].Value = isCheckedAll;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, _CURRENT_FORM_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}While i am using the DatagridViewCheckBoxHeaderCell class created as per this link: http://www.codeproject.com/Articles/20165/CheckBox-Header-Column-For-DataGridView
but I am having trouble to:
1. Untick the header check box when user unchcecks any of the checkboxcell in my datagridview.
2. when all the checkboxes ticked in datagridview, the header check box should be ticked.
Appreciate your help in advance.