Hello House,
i am working with datagrid that has a level checkbox of which if it is checked others checkbox in the datagrid will also be checked (just the same way yahoomail works), that is working fine for me, i am having issues unchecking the top level checkbox if any of the checkboxes is unchecked, please i need your assistance. here is my code:
Global variables:
CheckBox chkbox=new CheckBox( );
DataTable dt = new DataTable( );
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns.Clear( );
DataGridViewCheckBoxColumn colCB = new DataGridViewCheckBoxColumn( );
colCB.Name = "chkcol";
colCB.HeaderText = "";
colCB.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns.Add( colCB );
Rectangle rect = this.dataGridView1.GetCellDisplayRectangle( 0, -1, true );
chkbox.Size = new Size( 18, 18 );
rect.Offset( 43, 2 );
chkbox.Location = rect.Location;
chkbox.CheckedChanged += chkBoxChange;
this.dataGridView1.Controls.Add( chkbox );
DataRow dr = default( DataRow );
dt.Columns.Add( "eno" );
dt.Columns.Add( "empname" );
dt.Columns.Add( "sal" );
dr = dt.NewRow( );
dr["eno"] = 101;
dr["empname"] = "test1";
dr["sal"] = 9000;
dt.Rows.Add( dr );
dr = dt.NewRow( );
dr["eno"] = 102;
dr["empname"] = "test2";
dr["sal"] = 15000;
dt.Rows.Add( dr );
dr = dt.NewRow( );
dr["eno"] = 103;
dr["empname"] = "test3";
dr["sal"] = 20000;
dt.Rows.Add( dr );
dataGridView1.DataSource = dt;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
double k = 0.0;
if ( e.ColumnIndex == 0 )
{
dataGridView1.CommitEdit( DataGridViewDataErrorContexts.Commit );
for ( int i = 0 ; i <= dataGridView1.RowCount - 1 ; i++ )
{
if ( Convert.ToBoolean( dataGridView1.Rows[i].Cells["chkcol"].Value ) == true )
{
k = k + Convert.ToDouble( dataGridView1.Rows[i].Cells[3].Value );
}
}
}
}
any assistance will be appreciated thanks.