# SetFocus Problem

**URL:** <https://forum.xojo.com/t/setfocus-problem/14725>\
**Category:** Getting Started\
**Created:** [March 3, 2014, 2:27pm UTC](https://forum.xojo.com/t/setfocus-problem/14725 "2014-03-03T14:27:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [March 3, 2014, 2:27pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/1 "2014-03-03T14:27:03Z")

</div>

I instantiate NewWindow from DetailWindow so I can use it to create, update, delete, several tables in a database (e.g. customers, suppliers, ZIP codes,). On DetailWindow there is one Listbox, one Label and one Textfield. The Listbox is dynamically files with the data from the table. Labels and Textfield are dynamically (Control sets) generated based on the number of columns in the ListBox. This works well

When making the Window visible, I want to set the focus on the first row of the ListBox (ListBox1.SetFocus) .However the focus always starts on the first Textfield. Tabbing works well and goes through all textfields and ends on the ListBox. When reaching the ListBox, tabbing is not available anymore. What’s is going wrong? How to set focus on ListBox when starting the window? How to reactivate the tabbing when the focus reaches the ListBox?

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 3, 2014, 4:16pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/2 "2014-03-03T16:16:23Z")

</div>

> [@68960:@Carlos De Backer](#):
>
> When making the Window visible, I want to set the focus on the first row of the ListBox (ListBox1.SetFocus) .However the focus always starts on the first Textfield. Tabbing works well and goes through all textfields and ends on the ListBox. When reaching the ListBox, tabbing is not available anymore. What’s is going wrong? How to set focus on ListBox when starting the window? How to reactivate the tabbing when the focus reaches the ListBox?

Have you made sure to set ListBox1.Tabindex to 0 ?

---

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [March 3, 2014, 4:18pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/3 "2014-03-03T16:18:54Z")

</div>

Michel, yes. TabIndex for the ListBox=0, TabIndex for the Textfields=1,2,3…

---

<div class="post-metadata">

**Author:** ![Will\_Shank](https://forum.xojo.com/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@Will\_Shank](https://forum.xojo.com/u/Will_Shank)\
**Post date:** [March 3, 2014, 4:51pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/4 "2014-03-03T16:51:32Z")

</div>

What OS? I have the same focus problem in a Cocoa app but it works correctly in Carbon. My ugly workaround was to start a single-shot short-period timer at the end of Open which just sets the focus.

---

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [March 3, 2014, 4:55pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/5 "2014-03-03T16:55:47Z")

</div>

Will, I develop the application on MAC OS X 10.7.5

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [March 3, 2014, 4:56pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/6 "2014-03-03T16:56:46Z")

</div>

[Tab Order Change in Real Studio 2012r1](http://www.realsoftwareblog.com/2012/08/tab-order-change-in-real-studio-2012r1.html)

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 3, 2014, 5:03pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/7 "2014-03-03T17:03:09Z")

</div>

> [@68987:@Carlos De Backer](#):
>
> Michel, yes. TabIndex for the ListBox=0, TabIndex for the Textfields=1,2,3…

I created a small test project, and you are right, it goes to the textfield, although the listbox is tabindex 0.

Tried to set the focus in the open event, did not work.

What I found working is to create a boolean window called gothefocus and added this in the textfield GotFocus event :

`Sub GotFocus()
  if gotthefocus = false then
    ListBox1.setfocus
    gotthefocus = true
  end if
End Sub
`

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [March 3, 2014, 5:18pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/8 "2014-03-03T17:18:40Z")

</div>

Eli, Thank you. Do you know they already changed this in Xojo?

[quote]UPDATE: After considering feedback from the community, we have decided to rollback this change in R1. We are working on an update (R1.1) that will re-enable the ability to set the tab order once again. We have found a way to provide the default tab order along with a custom tab order option (the one you have now) which we will add to a future version[/quote].

---

<div class="post-metadata">

**Author:** ![Carlos\_De\_Backer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@Carlos\_De\_Backer](https://forum.xojo.com/u/Carlos_De_Backer)\
**Post date:** [March 3, 2014, 5:20pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/9 "2014-03-03T17:20:06Z")

</div>

Michel, this workaround solves the problem. But, is this (still) a bug in Xojo?

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [March 3, 2014, 6:15pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/10 "2014-03-03T18:15:09Z")

</div>

> [@69017:@Carlos De Backer](#):
>
> Michel, this workaround solves the problem. But, is this (still) a bug in Xojo?

Looks like a bug. I encountered it before.

Filed a report # 32520

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:06pm UTC](https://forum.xojo.com/t/setfocus-problem/14725/11 "2020-10-29T17:06:20Z")

</div>


