Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
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)
Form1 frm = new Form1();
int numofRows = (dataGridView1.RowCount)-1;
frm.countedRows = numofRows.ToString();


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

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
dataGridView1.CurrentRow.Cells[4].Value

code.

Is this code a problem?
Posted
Updated 4 days ago
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The problem is almost certainly due to this line:
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:
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[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100