Using: C# Forms VS2015
What I'm trying to do:
- On form1, I have a textbox (tbJobTitle) and a button (bChooseJobTitle -> form2) for a "Job Title" of an employee.
- The textbox(enabled=false) displays the chosen Job Title of an employee.
The button bChooseJobTitle opens another form (form2) that has a datagrid and 2 buttons (Choose & Cancel)
using System.Threading; ... Thread the1; ... private void bChooseJobTitle_Click(object sender, EventArgs e) { the1 = new Thread(OpenNew_tblJobTitle); the1.SetApartmentState(ApartmentState.STA); the1.Start(); } private void OpenNew_tblJobTitle(object obj) { Application.Run(new form2()); } ...
I initially set a global string MyVar.Employee_Choose_idJobTitle (default "" ) to store the choosen index primary key if the user selected content and click the Choose button. If the Cancel button is click the MyVar.Employee_Choose_idJobTitle will remain = "".
//... at form2 "Choose" button private void bChoose_Click(object sender, EventArgs e) { MyVar.idJobTitle = dataGridView1.CurrentRow.Cells[0].Value.ToString(); this.Close(); } private void bCancel_Click(object sender, EventArgs e) { this.Close(); }
- When form2 is closed either by "Choose" button or "Cancel" button, the focus goes back to form1's bChooseJobTitle button.
How do I trigger this event?
...so that can test if the content of MyVar.idJobTitle is not null and add the proper value to my textbox.
I was looking for the button events like onFocus or activate but could not find any. Do I use form events instead to do this?