1
I am trying to add the data from one line of a Datagridview from one form to another by clicking on a "confirmation button", but by the searches I did in other similar cases, the code is correct. Even so, I have no return code.
Here’s what I’m doing:
Form2.TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString()
The data should appear in the text box of the other form when I click on a button. What’s wrong? The return I have is "nothing". There is no error, but it doesn’t work either.
-Did you remember to set Textbox’s "Modifiers" property to public? -Gave a form2.Datagridview1.Refresh()? Note: Remembering that exchanging values between Forms in this way that you are doing is very "dependent". You need to "uncouple" this dependency. I create a public property in form2 and make an Handler that when the property changes there in form2, already updates what is needed there. There are several ways to do it. Read the book "Use Your Head - Project Patterns". There are several common problems and how they were solved.
– Diego Sayron
I suggest checking two things: 1. Is the value already stored in the cell when you run this line? Maybe you need to call
DataGridView1.EndEdit
before executing it. 2. You are referring to the right instance ofForm2
? It may be necessary to change toMy.Forms.Form2.Text = ...
– VBobCat