well, for the solution of this problem i would like to follow some other way.
Step-1: in
frmHelp
, declare a string variable say named
companyName
. Now, encapsulate the variable (Right click on the variable, then go to Refactor and then click Encapsulate Field. Click OK.) You'll find that something like below:
public String CompanyName
{
get { return companyName; }
set { companyName = value; }
}
Step-2: after encapsulating when you work with
ListBox.SelectedIndexChanged
event. Code like below:
private void YourListBoxName_SelectedIndexChanged(object sender, EventArgs e)
{
this.companyName=YourListBoxName.SelectedItem.ToString();
}
Step-3: Now, get into frmItem, where you have textbox for Company Name (
txtCompany
). Here, according to your way, on
TextBox.Enter
event call frmHelp like below:
public void txtCompany_Enter(object sender, EventArgs e)
{
frmHelp fh=new frmHelp();
fh.ShowDialog();
if(fh.CompanyName!=String.Empty)
txtCompany.Text=fh.CompanyName;
else
txtCompany.Text="";
}
Remember:
**Use Form.ShowDialog() only while calling the frmHelp.
**When user closes the frmHelp after selecting the listbox in frmHelp, you'll have the value in text box of the frmItem.