Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
I have one more question again.

I want to pass the data in current row`s selected cell.
I have two form.
One`s name is from1 and another`s name is form2.
I get a data from form2.(Data was counted rows)
And, I used this code to give data to form1.

(form2)
C#
Form1 frm = new Form1();
int numofRows = (dataGridView1.RowCount)-1;
frm.countedRows = numofRows.ToString();


Next, I goto Form1`s code, and write this code.

C#
public string countedRows;
.
.
dataGridView1.CurrentRow.Cells[4].Value) = countedRows;


The first line was succeed, but no data was entered from the next line.
It just had error.


What can I do this state.

What I have tried:

I used
C#
dataGridView1.CurrentRow.Cells[4].Value

code.

Is this code a problem?
Posted
Updated 11-Sep-19 21:19pm
v2

1 solution

The problem is almost certainly due to this line:
C#
Form1 frm = new Form1();
Which create a new instance of yoru form, which is not connected to the one the user is looking at, and is never even displayed, according to the code you show us. That won;t work - you need to talk to the actual instance the user is working with.

Have a look at these, one of them will fit your circumstances.
The form that creates an instance of another:
C#
MyForm mf = new MyForm();
mf.Show();
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)

Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
Share this answer
 

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