passing values from one child form to another; input validation

  • Thread starter Thread starter Vaughn
  • Start date Start date
V

Vaughn

In my MDI, I have a child form (frm_emp) that on a button click, displays
another child form w/ a listview (frm_list). I had two questions:

1) Assuming I already have the emplcode the user clicked on frm_list, how
would I be able to transfer that value back to frm_emp?
2) From within the double-clicked event in the frm_list, can I send the
emplcode value to frm_emp *and* execute a public method in frm_emp. It'd be
basically something like this (I know this code doesn't compile):
public String _myEmplcode = "";
private void btn_accept_Click(object sender, System.EventArgs e)
//clicked event in frm_list
{
frm_emp.empcode.Text = _myEmplcode; contains valid emplcode
frm_emp.RunThisMethod(); //RunThisMethod is public
this.Dispose(); //I'm done with the frm_list so I dispose.
}

I was also thinking if it's possible to validate the input in frm_emp.Text.
On the TextChanged property of the textbox, can I check to see where the
input came from and run a method according to the result? I'd be asking: if
the textbox input came from the value the listView returned, execute X
method. Otherwise (eg. the user entered a manual emplcode), do nothing.

Thank you.
 
There's a lot of ways you can do this. One is to pass a refference to your
current frm_emp when you create and show your frm_list. Then just use that
reference to do whatever you want.

-JG
 
Thanks for the info.
And how would I be able to validate how the textbox got filled?
As soon as the textbox's filled with the emplcode that the user
double-clicked in the listbox , I'd like to be able to execute several
methods that would *not* be called if the user enters the emplcode by hand.
Is there some way that I can check how the textbox got filled? Someone
suggested validation events but I don't know how to call them.

Thanks again.
 
Someone suggested validation events but I don't
know how to call them.

In this case, your validation event handler should call your validation
method:

// validate event handler
public void theTextBox_validate(...) {
this.checkTheTextBox(...);
}

public void checkTheTextBox(...) {
// actually do the checking
}

and then you just call the later method whenever you want to.

Hope that helps,
-JG
 
Back
Top