SetFocus on ListBox in ContainerControl

I created ListBox1 in ContainerControl1 . I have put ContainerControl1 on DetailWindow at design time (in the IDE) and got the name ContainerControl11. Now I try to set the focus on the ListBox with:

DetailWindow.ContainerControl11.ListBox1.ListIndex=0 DetailWindow.ContainerControl11.ListBox1.SetFocus

Problem: ListBox1 doesn’t get the focus…

Where is above code located in your project?

The code is in one of the menu handlers of MainWindow.

You can only use SetFocus if the window is the active one. So you must first make DetailWindow active:

DetailWindow.Show() DetailWindow.ContainerControl11.ListBox1.SetFocus()

These were the statements I had in the menu handler:

DetailWindow.ShowModal DetailWindow.ContainerControl11.ListBox1.ListIndex=0 DetailWindow.ContainerControl11.ListBox1.SetFocus()

But the ListBox doesn’t get the focus

Try moving “DetailWindow.ContainerControl11.ListBox1.SetFocus()” to either the Open or Activate event of DetailWindow.

Tried it… But no result. I don’t know what’s going on: It’s even impossible to set the focus on the close button of DetailWindow:

DetailWindow.CloseButton.SetFocus()

XOJO is so strange when you have 10 years of experience in Java!

ShowModal pauses execution, so the following lines won’t be executed until after DetailWindow closes.

Have you any idea how I can set the focus on the ListBox or on another control? How can I solve this problem?

As Tim said ShowModal shows the window MODAL and executes code in that window until it closes - only then does code execution continue after the ShowModal. So how about the Open event of the ShowDetail window? Seems the logical place for it.

Or reverse the lines of code:

DetailWindow.ContainerControl11.ListBox1.ListIndex=0
DetailWindow.ContainerControl11.ListBox1.SetFocus()
DetailWindow.ShowModal

Tim and Markus… Thank you for the suggestions… But even these suggestions don’t work. I removed the Container Control and did put the ListBox1 directly (without Container Control) in DetailWindow. This works well… However, I did want to use one DetailWindow with one ListBox, dynamic generated Labels and dynamic generated TextFields to manage (Create, Update, Delete) records in several database tables (e.g. table customers, table suppliers,…). It seems now, I will have to create a DetailWindow for Customers, a DetailWindow for Suppliers… With my Java and C++ experience, this seems so strange to me…