Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have formA and formB.

In formA there is textboxA and in formB there is textboxB.
FormA also has a button, named buttonA, and upon clicking buttonA I am calling formB.

formB.ShowDialog()

In formB the value of textboxB will be passed to textboxA upon closing formB.

My problem is textboxA remains blank even though in my debug states that it's passing a value to textboxA.
However, it's not displaying any value.

Thanks in advance
Posted
Updated 17-Oct-11 21:24pm
v2
Comments
Vivek Krishnamurthy 18-Oct-11 3:16am    
Please post the code you have written so far. That would help you better to get it resolved.
Dalek Dave 18-Oct-11 3:24am    
Edited for Grammar, Syntax and Readability.

The way to do this is to create a public property in FormB which loads the TextBox:. You then load it before the call to ShowDialog, and retrieve it after the form has closed:
VB
Public Property myValue() As String
    Get
        Return textboxB.Text
    End Get
    Set
        textboxB.Text = value
    End Set
End Property


VB
Dim fb As New FormB()
fb.myValue = textboxA.Text
fb.ShowDialog()
textboxA.Text = fb.myValue
 
Share this answer
 
Comments
farout9999 18-Oct-11 4:25am    
thanks got the value showing up
This just works.. try it

Form1

C#
private void button1_Click(object sender, EventArgs e)
{
    Form2 f2 = new Form2();
    DialogResult res = f2.ShowDialog();

    if (res == DialogResult.OK)
    {
        textBox1.Text = f2.TextBoxValue;
    }
}


Form2

C#
private void button1_Click(object sender, EventArgs e)
{
    this.DialogResult = DialogResult.OK;
    this.Close();
}

public string TextBoxValue { get { return textBox1.Text; } }


button1 and textBox1 are controls on the Form1 and Form2.

PS: Control names are for ref only.

Not sure why this was an issue.
 
Share this answer
 
This is very easy stuffs. Please try with that,


you need to write this code on the Button click event in FormA. And txtB is the text of FormB where as txtA is the text box of FormA.

XML
private void btnOK_Click(object sender, EventArgs e)
        {
            FormB frmB = new FormB();
            DialogResult result= frmB.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                this.txtA.Text = frmB.txtB.Text;
            }
        }


Here you need to make the access modifier of txtB is public. That is,

C#
public System.Windows.Forms.TextBox txtB;
 
Share this answer
 
v2
Comments
Md. Rashim Uddin 18-Oct-11 3:46am    
Please try with that...it is working in my end

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