Currently, I am doing a project. I don't know how to pass a value from one windows form to another windows form using c#.net. Suppose, I have two form: parent form and child form. Parent form consists of a datagridview now datagridview cell click child form is open Now in child form also a Datagridview containing the three columns last one is checkbox. when i checked the checkbox I want to pass selected item (Selected row and column 2 value) of datagridview to my parent datagridview form without closing the child form.

Hi ,
Thanks for reply actually i done this by creating an instance. But its not working.

Show us a piece of your code and tell where it is not working.

In the CellContentClick event of DataGridview in your child form, you need to write the code.

In the event you need to create the object of your Parent form. Now once you have object of your Parent form, you can access public field of your parent form. Set the value of that field with datagridview selected row's column value and call the Show( ) method of your parent form.

your code looks like below

DataGridViewRow objGR = dataGridView1.SelectedRows[0];
Form5 objFrm5 = new Form5();
objFrm5.textBox1.Text = objGR.Cells[2].Value.ToString();
objFrm5.Show();

that's all..

Currently, I am doing a project. I don't know how to pass a value from one windows form to another windows form using c#.net. Suppose, I have two form: parent form and child form. Parent form consists of a datagridview now datagridview cell click child form is open Now in child form also a Datagridview containing the three columns last one is checkbox. when i checked the checkbox I want to pass selected item (Selected row and column 2 value) of datagridview to my parent datagridview form without closing the child form.

hi, rohand
When i create a instance of parent form it will take a new form of parent. suppose parent form datagrid contains 10 rows i will click on 2 row and child form is open then
on child form create an instance as you say but when creating an instance parent datagrid shows rowcount as 1. how to figure out this problem

Would you please explain a bit better what would you like to pass where. You only said you have 2 forms, on both there are dataGridViews. And when you add a tick onto dgvCheckBoxColumn this exact row`s data has to pass to another form.
Can you please explain Exactly what you want to do.
then I can help you out,
Mitja

Ok... I will explain in detail

My parent form is PrintForm and child form is QuestionSelection. In my parent form one datagrid is their containing columns like

Sr. No. | Question | Subject | Chapter |


In Question column i am displaying the Question type like

Sr. No. | Question | Subject | Chapter |
Select Appropriate option

Now when i am clicking on Select Appropriate option child form is opened containing the questions related to type.

In child columns are

Sr No. | Questions | Selected

in selected their is checkbox for selecting questions after selecting checkbox Question value assigned to parent form Question.

(Actually i am figure it out by taking array but is their is another way)
Hope you will understand

I read your upper post a couple of times, but still don`t get it exactly what you would like to do.
Please make it simple, and dont try to examplin in details.
Do it like:
On form1 dgv has columns: a,b,c
On Form2 dgv has columns: x,y,z

When user add a tick in a dgv on form1, form2 has to open...
and something like it.
Dont complicate.
Sorry, but from your upper explanation, I count get a clue what exactly would you like to do.
If its simplier list with dashes.

Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.