Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In Form1(Parent) i add DataGridView and it contents 10 rows. and column[5] is CheckBox, and this CheckBox is ReadOnly.
when double click on Row1 the Form2(Child) open and Checkbox checked, and when close Form2 the Checkbox unchecked, ect.
How Checkbox unchecked when Form2 is Closing? plz help!

What I have tried:

private void datagridview1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
Form2 form = new Form2();
datagridview1.CurrentRow.Cells[5].Value = true;
form.MdiParent = this.MdiParent;
form.Show();
form.FormClosing += Frm_FormClosing
}

private void Frm_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (Form frm in Application.OpenForms)
{
foreach (DataGridViewRow row in datagridview1.Rows)
{
if (frm.Text == row.Cells[1].Value.ToString())
{
row.Cells[5].Value = null;
}
}
}
}
Posted
Updated 23-May-21 6:18am

1 solution

You don't set the Text property of the Form2 instance when you create it, so unless by pure luck one of your forms has text that matches the cell nothing will happen.

Why not use the sender parameter to identify the instance of the form that closed: it's set for you by the system for that purpose!
That way, it should be relatively simple to identify if rows should be reset.
 
Share this answer
 
Comments
User_Michel 23-May-21 12:36pm    
Thanks for your reply, can you give me an example code? sorry, i am beginner.
OriginalGriff 23-May-21 12:37pm    
if (sender is Form2 frm)
   {
   ...
   }
User_Michel 23-May-21 12:47pm    
where i put this code? Complete it Please..
OriginalGriff 23-May-21 13:40pm    
We aren't here to do it all for you: you should know what that code does by now, it you are dealing with MDI forms and such.

Have a go and see if you can work it out for yourself.
User_Michel 23-May-21 13:48pm    
Ok. i tried many times, and if i can doing it with my self, i did not ask here. now i gave up. thank you again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900