Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Value Between WinForms

Status
Not open for further replies.

Anddmx

Technical User
Apr 26, 2004
56
0
0
US
Hi,

I'm haven some problems moving value from winForms.

I have Textbox with hold propertyID and I need to move this value to form2 to finish running my query. Only problem is value comes over as NULL. Not sure what I'm doing wrong I have use GET / SET property few other times but not with winForms. When I debug I get "" for value from PropertyID.

CODE:

form1:

public string PropertyID
{
get { return propertyID.Text; }
}

form2:
form1 form1 = new form1();
string PropertyID = form1.PropertyID;


Thanks CLA
 
When you create a new instance of form1 inside form2 using the new operator, it initalizes PropertyID to empty string. What you need is a reference to the original instance of form1. Or at least the original value.

The technically correct way to do this is have the ownership of the forms contained in another class. It takes the value the user entered, and passes it onto the other form.

Code:
public AnddmxController
{
  public ProcessInput()
  {
    string propVal;
    form1 frm1 = new form1();
    frm1.ShowDialog();
    propVal = frm1.PropertyID;

    form2 frm2 = new form2();
    frm2.PropertyID = propVal;
    frm2.ShowDialog();

    if (frm1 != null)
      frm1.Dispose();
    if (frm2 != null)
      frm2.Dispose();
  }
}

Hope this helps.
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi chiph,

Thanks you for the reply.

Its still not working. I've tried everything I know to make this work.
 
this should be simple and chiph example should have worked? can you post your RELEVANT code what you have at the minute.

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top