0
I am making a program in c# and I have a datagridview at Form1
and I have another datagridview on Form2
. How can I get the selected cell from the datagridview that is in Form1
and use na as a variable in Form2
or wanted to use the variable test
in another Form
This is how I’m going to get the values of the cells in datagridview:
if (dataGridViewEnviarDados.SelectedRows.Count > 0)
{
foreach (DataGridViewRow r in dataGridViewEnviarDados.SelectedRows)
{
string test = r.Cells[0].Value.ToString()
}
}
@LINQ I am not intending why my question is duplicated when half of the answers have to do with Textboxs
– Pedro Azevedo
A control is a control. Whether it’s textbox or combobox or radiobutton or anything. If I understand correctly, you want to use elements of one form in another form, that has been asked thousands of times here.
– Jéf Bueno
@But that doesn’t help my case
– Pedro Azevedo
So be more specific and explain the problem in detail. With the information you gave, your question is duplicated. When you edit it, mention me so I can reopen it if that’s the case.
– Jéf Bueno
@LINQ I’ve already edited
– Pedro Azevedo
Your question is answered here: https://answall.com/questions/166563/passar-informa%C3%A7%C3%b5es-entre-Forms-do-c
– Jéf Bueno
@LINQ Can you give an example for my question? I was too confused by the answers given in the questions you mentioned
– Pedro Azevedo
The selected answer (which happened to be me who wrote it) is the example you need.
– Jéf Bueno
@LINQ I’m not intending your answer sorry... I was a little confused by the large amount of examples you gave but thank you very much for your cooperation
– Pedro Azevedo
Basically you will make the variable
test
is a public property of the form. So you can access from "outside"– Jéf Bueno
Can you make an example with that code for me please
– Pedro Azevedo
@LINQ I’ve been reading again the example you mentioned and in my opinion are different characteristics because I need information that is in the variable (test) from Form1 to use in form2 I wanted to know how to put the variable test to public but defining that it will have the contents of cell 2 from datagridview from Form1 understood ?
– Pedro Azevedo