Home All Groups Group Topic Archive Search About

Problem with setting focus

Author
6 Jan 2006 3:30 PM
Darrell Wesley
I have an application with 2 forms. Form1 is the main form and has 2 text
boxes on it. Form2 is a datagrid showing a list of workorders that are to be
manufactured.

The user can use the mouse to select the work order on form2 and data is
populated on form1 with the partid and work order. It is then supposed to
shift Focus to form1 and the text box containing the workorder BUT focus is
being kept on Form2.

What do I need to do to properly get the focus to change?

Heres the code used to change focus:

  Form1.txtWorkOrder.Focus ()

Author
6 Jan 2006 3:47 PM
Herfried K. Wagner [MVP]
"Darrell Wesley" <DarrellWes***@discussions.microsoft.com> schrieb:
>I have an application with 2 forms. Form1 is the main form and has 2 text
> boxes on it. Form2 is a datagrid showing a list of workorders that are to
> be
> manufactured.
>
> The user can use the mouse to select the work order on form2 and data is
> populated on form1 with the partid and work order. It is then supposed to
> shift Focus to form1 and the text box containing the workorder BUT focus
> is
> being kept on Form2.
>
> What do I need to do to properly get the focus to change?

Call the form's 'Activate' method prior to calling the control's 'Focus'
method.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
6 Jan 2006 4:04 PM
Darrell Wesley
I added form1.activate to the code but focus is still being retained on
form2. What else may be causing this behavior?   (The same application in VB6
works just fine - this is in VB2003)

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Darrell Wesley" <DarrellWes***@discussions.microsoft.com> schrieb:
> >I have an application with 2 forms. Form1 is the main form and has 2 text
> > boxes on it. Form2 is a datagrid showing a list of workorders that are to
> > be
> > manufactured.
> >
> > The user can use the mouse to select the work order on form2 and data is
> > populated on form1 with the partid and work order. It is then supposed to
> > shift Focus to form1 and the text box containing the workorder BUT focus
> > is
> > being kept on Form2.
> >
> > What do I need to do to properly get the focus to change?
>
> Call the form's 'Activate' method prior to calling the control's 'Focus'
> method.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
10 Jan 2006 3:59 PM
Darrell Wesley
As it turns out the "Click" event and the "CurrentCellChanged" event were
being handled by the same routine. The problem appears to be in the
CurrentCellChanged area.

When I took the "currentCellChanged" out of the picture things worked as
expected but now I have to click in the extreme left hand column where the
row indicator is, clicking inside a cell in the grid has no effect. If I add
a call to the Click event handler the same problem would show up (appeared as
if both events were being riggered).



Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Darrell Wesley" <DarrellWes***@discussions.microsoft.com> schrieb:
> >I have an application with 2 forms. Form1 is the main form and has 2 text
> > boxes on it. Form2 is a datagrid showing a list of workorders that are to
> > be
> > manufactured.
> >
> > The user can use the mouse to select the work order on form2 and data is
> > populated on form1 with the partid and work order. It is then supposed to
> > shift Focus to form1 and the text box containing the workorder BUT focus
> > is
> > being kept on Form2.
> >
> > What do I need to do to properly get the focus to change?
>
> Call the form's 'Activate' method prior to calling the control's 'Focus'
> method.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>