Pass DataGridView selected cell value to TextBox in another Form

tdignan87

Member
Joined
Jul 8, 2019
Messages
14
Programming Experience
Beginner
Hi
I have the following code; although its not passing the value. Can anyone give me some guidance please?
AdjustCodeTxtBox is returning with no data.
C#:
 ISForm myForm = new ISForm();

              

              

                 ProductDGV.CurrentRow.Cells[0].Value = myForm.AdjustCodeTxtBox.Text;
                this.Close();
 

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
214
Location
Virginia Beach, VA
Programming Experience
10+
I assume there is a reason you are creating a new instance of ISForm(). Are you calling ShowDialog() or Show() on that instance at some point to actually display that form instance and have it interact with the user?
 

tdignan87

Member
Joined
Jul 8, 2019
Messages
14
Programming Experience
Beginner
Hi Mate.
Yeah ISform is the main form; they click a button that opens another form containing the datagridview. the user puts in a filter; selects the row and that data needs to go back to the main form and populate the textboxes.
ShowDialog is used to open the form containing the code I posted.
 

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
214
Location
Virginia Beach, VA
Programming Experience
10+
Remember that assignment operator works from right to left. The left hand side is the destination. The right hand side is the source. This like of code:
Code:
ProductDGV.CurrentRow.Cells[0].Value = myForm.AdjustCodeTxtBox.Text;
is taking the value from the text box and assigning it to a cell in the data grid view. Based on your title and your last post, it sounds like you want the opposite: go from data grid view cell to the text box. That means the sides need to swapped.
 

tdignan87

Member
Joined
Jul 8, 2019
Messages
14
Programming Experience
Beginner
Hi Skydiver
No sorry its taking the value from the dgv selected row, and placing it in the textbox.
So basically
1. op opens form
2. Op clicks button that opens the datagridview with search filter. Op filters out and selects the cell in the DGV
3. DGV closes and puts the selected cell value into the textbox.

Thanks
 

tdignan87

Member
Joined
Jul 8, 2019
Messages
14
Programming Experience
Beginner
Yeah i changed the code to
C#:
myForm.AdjustCodeTxtBox.Text = this.ProductDGV.CurrentRow.Cells[1].Value.ToString();
                this.Close();
Still returns nothing to the textbox.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,286
Location
Sydney, Australia
Programming Experience
10+
Here's one I created earlier. 11 years earlier.

 
Top Bottom