Prakash Mondal

Prakash Mondal

  • NA
  • 288
  • 209k

How to use checked and unchecked event in dataGridView?

Oct 6 2018 12:27 PM
I used checkbox in dataGridView.
 
I want to when I checked then a confirm box will appear, if you choose No then checkbox will unchecked.
 
my code:
 
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

if (e.ColumnIndex == 0)
{
if (Convert.ToBoolean(dataGridView1.Rows[e.RowIndex].Cells["chkBox"].EditedFormattedValue) == true)
{
bool flag = false;
string action = MessageBox.Show("After Process, This Record Will Invalid. Do You Continue?", "Alert!", MessageBoxButtons.YesNo, MessageBoxIcon.Information).ToString().ToString();
if (action == "Yes")
{
flag = true;
}
else if (action == "No")
{
flag = false;
}
if (flag)
{
MessageBox.Show("OKOK");
}
else
{


}
MessageBox.Show("Checked: " );
}
else
{
MessageBox.Show("Un-Checked: ");
}
}
 
And another is when dataGridView is loading then the checkboxes will checked or unchecked depends of a flag.
 
Please help me.

Answers (3)