Populating Textbox in different form with Datagridview data

Asked

Viewed 95 times

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.

  • 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 of Form2? It may be necessary to change to My.Forms.Form2.Text = ...

1 answer

0

Friend try to check if what you are picking up from Datagridview1 is returning something!

Dim teste = DataGridView1.CurrentRow.Cells(0).Value.ToString()

With the test variable you can conclude that either the error is in Datagridview1 or the error is when you are trying to pass the value to the Form2 Text Box. Then try passing the test value to the Form2 Text Box

Form2.TextBox1.Text = teste

Hope it helps or minimize problems!

Browser other questions tagged

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