Click here to Skip to main content
15,179,246 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.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;
Updated 23-May-21 7: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.
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.
OriginalGriff 23-May-21 13:58pm
It took you eight minutes (or less) to "try many times"?

Hmmm. Why do I get the feeling that means "I don't want to have to think about this, do it for me"?
User_Michel 23-May-21 14:20pm
I am talk about FormClosing code (many days) not your reply, because i do not understand it. and i know this is my problem.
A general advice, the answers must be depend on who asking, if he beginner or advanced..
OriginalGriff 24-May-21 3:01am
A general advice: if you don't know what you are doing, tell people instead of trying to come over as someone who has a specific problem.

Unless we know your skill level - and we don't, all we get is exactly what you type - we have to make assumptions. And then you come over as an arrogant idiot (which I'm sure you aren't in the real world) because instead of saying "I don't know what I'm doing; I don't understand" you just politely order us to complete your code for you.

Do you see what I mean here?

Let's wipe the slate clean and start again ...

Hi there! Welcome to the site!
Would you like to explain what you are trying to do (not what code you are trying to write because I don't think you are on the right track at all!) in English, and tell us where you are having difficulties?

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