Board index » delphi » Combobox in MDI form, focus in MDI child

Combobox in MDI form, focus in MDI child

hello,
  I have a MDI application...
in the mdi form, I have some comboboxes. picking items in the comboboxes
(OnChange) will affect the active MDIChildwin, and then SetFocus back to the
MDIChild. no problem at all.

but, if I change the items property or ItemIndex property(to update the list
and default to 0), I cannot programmatically set focus to the MDI child. I
tried
ActiveMDIChild.SetFocus;
and/or
TMyChildWin(ActiveMDIChild).scrollbar1.SetFocus;
apparently the focus is set correctly, but pressing Page up/down, arrow key
still affect the combobox on MDIparent, not the child's scrollbar.

only a mouse click on the scroll bar will correctly set the focus, no matter
the scrollbar's up, down or position button.

I tried to post mouseup, mousedown messages to the scrollbar, no luck.
any hints?

 

Re:Combobox in MDI form, focus in MDI child


"Ka Chun, Cheng" <kccheng_gog...@biblecrawler.com> wrote:

Quote
>  I have a MDI application...
>in the mdi form, I have some comboboxes. picking items in the comboboxes
>(OnChange) will affect the active MDIChildwin, and then SetFocus back to the
>MDIChild. no problem at all.

>but, if I change the items property or ItemIndex property(to update the list
>and default to 0), I cannot programmatically set focus to the MDI child. I
>tried
>ActiveMDIChild.SetFocus;
>and/or
>TMyChildWin(ActiveMDIChild).scrollbar1.SetFocus;
>apparently the focus is set correctly, but pressing Page up/down, arrow key
>still affect the combobox on MDIparent, not the child's scrollbar.

>only a mouse click on the scroll bar will correctly set the focus, no matter
>the scrollbar's up, down or position button.

>I tried to post mouseup, mousedown messages to the scrollbar, no luck.
>any hints?

This is not very clean. The problem is that you are still caught in a
focus transition. This code should allow the transition to occur as
soon as the first has cleared:

  PostMessage(ActiveMDIChild.Handle, WM_SETFOCUS, 0, 0);

Good luck.

Kurt

Re:Combobox in MDI form, focus in MDI child


thanks it work! so the trick is to pend the setfocus in the end of message
queue, instead of doing it right aways

Re:Combobox in MDI form, focus in MDI child


"Ka Chun, Cheng" <kccheng_gog...@biblecrawler.com> wrote:

Quote
>thanks it work! so the trick is to pend the setfocus in the end of message
>queue, instead of doing it right aways

Exactly. Windows becomes very confused if you attempt to change the
focus while Windows is already changing the focus.

Good luck.

Kurt

Other Threads