StrataFrame Forum

Changing FocusControlOnEdit value

http://forum.strataframe.net/Topic353.aspx

By Scott - 12/20/2005

I have a form that can be used in one of two ways.  One way control 1 gets focus, another way control 2 gets focus.  When I change the focuscontrolonedit value focus still goes to the control assigned in the designer.  Where should I be changing this value or is there another way that I should be doing this.

I am currently changing it in the BO's parentformloading.

By StrataFrame Team - 12/20/2005

Nope, you should be able to change the FocusControl properties at runtime... When Add() is called on the form, the method calls Add() on the primary business object, and then if the FocusControl property is not null, then it sets the focus to that control. Same for Edit(). If it's not letting you set the property at runtime, then something must be resetting it. You might post a few snippets from your app (like where you're setting the FocusControl property at runtime, and where you're calling add or edit) and I'll step through it to make sure something isn't going awry.
By Scott - 12/20/2005

In ParentFormLoading I am doing

UsersBO.FillByUserName(pLoadUserName);
this.FocusControlOnEdit = txtEmail;
UsersBO.Edit();

By Scott - 12/20/2005

If I don't call the edit and click the edit button on the form things work just fine.

If I want to put the form into edit mode as soon as it is displayed should I be calling edit on the form or the BO?

By StrataFrame Team - 12/20/2005

You have to call Edit() on the form... the edit on the BO just sets the BO in an editing state, while the Edit() on the form puts the BO in editing state and sets the focus control.
By Scott - 12/20/2005

Even calling the forms edit, it still doesn't select the correct field.  Is the ParentFormLoading method the correct place to be doing something like this?  Should I be doing it else where?

If I put the form into edit mode manually (clicking the edit button on the toolstrip) it works great.  It seems that once the form is displayed calling edit works as expected,  but calling edit from the parentformloading doesn't do what I want it to.

By StrataFrame Team - 12/21/2005

Oh, I didn't realize that you were calling the Edit() from the parent form loading, I thought you were just setting the FocusControl in the event handler. Yes, you will have to wait until the form is loaded and the controls are visible before focus can be set to them. If you were to manually call Focus() on a control in the event, it wouldn't focus, either. Generally, when we have to do something after the form is loaded, we will put a timer on the form and set the tick to about 5-20 ms, and in the form's Load event, we will set it to enabled. In the tick event, disable the timer, and do what you need to do.
By Scott - 12/21/2005

Works great.  Thanks for the info.
By StrataFrame Team - 12/21/2005

No problem... we use that trick when we have to do something that is very intensive (takes more than 3 seconds) because we can let the form display and then show a wait window while we're going the work.