Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Everyone,

i am working on windows application.

when user double click on the text box i am displaying the another form with datagridview.

when user select on the row. the selected row data has been send to the parent form.

i am able to send the values. but the values are not displaying on the textbox.

i have tried with the option like refresh, update the form but still it is not working.

kindly help me anyone.

thanks,
Posted
Comments
Ralf Meier 3-Jul-15 6:42am    
OK ... what about a little bit of code to see what you have done and how you have done it ?
Bitto kumar 6-Jul-15 23:21pm    
In form2 i am calling the form1.
Form1 f=new Form1();
f.PassvaluestoForm1(value1,value2);
this.close();
lukeer 3-Jul-15 9:02am    
Does the childform close when user selects a row? If so, you can simply store a value within the childform, give it a public read-only property and read that from parent after closing and before disposing child.
Bitto kumar 6-Jul-15 23:20pm    
Hi thanks for your reply.i have done the same what u have suggested but it is not working.here is my code. in this code am able to send the values to form1. But it is not displaying into the textbox. if i store the values in static variable and if i click any button it is displaying.

Form1 f=new Form1();
f.PassvaluestoForm1(value1,value2);
this.close();
kindly suggest me.
lukeer 7-Jul-15 4:20am    
It works the other way round.

What you're trying is to send data to the parent form. I suggested to let the parent form catch data from its child.

There's an error in your implementation, though: Your code creates a whole new Form1(); whereas it should use the existing form. But better to drop that approach altogether. Too much for a comment. Look at my answer.

Use this pattern:

C#
class ParentForm : Form
{
    private ShowChildForm()
    {
        ChildForm child = new ChildForm();
        child.ShowDialog();
        int interestingValue = child.InterestingValue;
        child.Dispose();
    }
}

class ChildForm : Form
{
    public int InterestingValue { get; private set }
}
No touching the parent form from child side. Child should not need to know anything about its parent. Just get instantiated, do what it is supposed to do (like setting its InterestingValue) and die in peace.

Meanwhile, the parent has to know about its child. It's the ParentForm that created the child, after all. So the parent is not harmed too much with the need to know what value it requests from its child.
 
Share this answer
 
Hello,
As you mentioned
"i am able to send the values. but the values are not displaying on the textbox."
we can help you out more effectively by seeing your code.
May be this suggestion will help you out:
Create datagridview cellcontentclick event and catch the row whose value you want in your textbox then assign the value to textbox with row and cell id of datagridview.

C#
if(e.RowIndex>=0)
{
DataGridViewRow r = this.datagridviewid.Rows[e.RowIndex];
textboxid.text = r.Cells[2].Value.ToString();
}


For more visit below link:
http://www.c-sharpcorner.com/Blogs/15388/display-selected-row-from-datagridview-to-textboxes-in-windo.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900