I’ve made a new form out of UD01Entry and I love the simplicity. However, I’m stuck trying to get my one textbox to load in focus. Nothing appears to get focus when it loads. I changed the tab index on all the controls so that my textbox is 0 and nothing else is. I’ve tried to use .Focus() on form load and form shown. I’ve read that some people have used the AfterAdapterMethod to steal the focus from Epicor’s default logic… but it appears since I am not actually using UD01 that it either doesn’t fire OR it also doesn’t work to force the focus. Any tips here?
I did this on my custom dashboard with this code:
private void MainController_Load(object sender, EventArgs args)
{
// Add Event Handler Code
MyPartNum.Focus();
}
Having said that, I am not using native fields or EpiBindings on my controls.
Thanks but that is not working for me. So I thought I would get clever and show a messagebox upon Form_Shown that says what the active control is…
private void UD01Form_Shown(object sender, EventArgs args)
{
// Add Event Handler Code
//jobNum_txt.Focus();
//UD01Form.ActiveControl = jobNum_txt;
//jobNum_txt.Select();
MessageBox.Show(UD01Form.ActiveControl.Name);
}
I get no message box. Interesting. Does that mean the Shown event isn’t executing?
Use
private void MainController_Load(object sender, EventArgs args)
I can’t say why that other event doesn’t work, but this main load event works for me!
OK. I agree. The load event does work and it revealed that the mainPanel1 was the active control when the form loaded. Simply using the .Focus() method did not change the Forms ActiveControl property. But… this DID work…
private void UD01Form_Load(object sender, EventArgs args)
{
// Add Event Handler Code
UD01Form.ActiveControl = jobNum_txt;
}
Thats a new one for me! Good find!
It’s likely not working because you did not wire up the event handler to the event procedure in your code.
This will work:
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
// End Wizard Added Custom Method Calls
UD01Form.Shown += UD01Form_Shown;
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
UD01Form.Shown -= UD01Form_Shown;
}
private void UD01Form_Shown(object sender, EventArgs args)
{
jobNum_txt.Focus();
}
Thanks for pointing this out. You’re right. I did not. I did use the Load event, however and I would’ve thought that required the same thing… and evidently it didn’t. Or maybe I just overlooked something.
“Load” is available in the events tab, “Shown” is not and must be wired up manually.
Hey thanks much @dr_dan , this helped a bunch. For others, here is how you can apply the ActiveControl property to native controls on most any screen:
private void StartReworkForm_Load(object sender, EventArgs args)
{
//Set default reason code
EpiDataView edvStart = (EpiDataView)(oTrans.EpiDataViews["Start"]);//gets your data view
edvStart.dataView[edvStart.Row]["ReworkReasonCode"] = "NCR";//sets the value new value of the customer ID
//Set focus to the Job # field
EpiTextBox txtJob = (EpiTextBox)csm.GetNativeControlReference("2233c0f7-d359-4959-8387-2a9b8395149b");
StartReworkForm.ActiveControl = txtJob;
}
you’re a wizard, Kevin. Thank you! This is what I needed to fix a UI thing today.
Not quite, but I’m working on it.