Friday 22 February 2013

check one checkbox at a time in a gridview column in window application


 private void DGVFormula_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (DGVFormula.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn)
            {
                bool state = Convert.ToBoolean(((DataGridViewCheckBoxCell)DGVFormula.Rows[e.RowIndex].Cells[e.ColumnIndex]).EditedFormattedValue);
                int intDemarcationID = Convert.ToInt32(((DataGridViewCheckBoxCell)DGVFormula.Rows[e.RowIndex].Cells[0]).EditedFormattedValue);

                if (state)
                {
                    BtnDelete.Visible = true;
                    foreach (DataGridViewRow dgvrow in DGVFormula.Rows)
                    {
                        if (Convert.ToInt32(dgvrow.Cells[0].Value) == intDemarcationID)
                        {
                            ((DataGridViewCheckBoxCell)dgvrow.Cells[e.ColumnIndex]).Value = false;

                        }

                    }
                }
                else
                {
                    BtnDelete.Visible = false;
                }
            }
}

No comments:

Post a Comment