How can I get information from a datagridview to use in another form

Asked

Viewed 287 times

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 Form2or 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

  • 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.

  • @But that doesn’t help my case

  • 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.

  • @LINQ I’ve already edited

  • Your question is answered here: https://answall.com/questions/166563/passar-informa%C3%A7%C3%b5es-entre-Forms-do-c

  • @LINQ Can you give an example for my question? I was too confused by the answers given in the questions you mentioned

  • The selected answer (which happened to be me who wrote it) is the example you need.

  • @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

  • Basically you will make the variable test is a public property of the form. So you can access from "outside"

  • Can you make an example with that code for me please

  • @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 ?

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.