# Dropdown selectedValue error on first visionWindowOpened

**URL:** <https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346>\
**Category:** Ignition\
**Created:** [March 13, 2018, 5:50pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346 "2018-03-13T17:50:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![francis.rainville](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francis.rainville](https://forum.inductiveautomation.com/u/francis.rainville)\
**Post date:** [March 13, 2018, 5:50pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/1 "2018-03-13T17:50:48Z")

</div>

On a visionWindowOpened script, I initialze the dropdown selectedValue with a custom property of the window. The dropdown is binded to an SQL query. I got a dropdown error each time the popup window open for the first time (java.lang.NullPointerException). I think the dropdown doesn’t have the time to run his query before the I set the selectedValue.

I tried to add a system.db.refresh(myDropdown, “data”) to force an dropdown dataset refresh at the begening of my visionWindowOpened script but I still have the error.

Once the window is opened for the first time (and the dropdown is populated), I don’t have the error anymore.

Is there a way to prevent the first error?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 13, 2018, 6:19pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/2 "2018-03-13T18:19:34Z")

</div>

The windowOpened event [is documented](https://docs.inductiveautomation.com/display/DOC79/Component+Events) to run before bindings for the window. You probably want to use internalFrameOpened or internalFrameActivated instead. (See the notes in the docs.)

---

<div class="post-metadata">

**Author:** ![francis.rainville](https://avatars.discourse-cdn.com/v4/letter/f/e8c25b/32.png) [@francis.rainville](https://forum.inductiveautomation.com/u/francis.rainville)\
**Post date:** [March 13, 2018, 6:42pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/3 "2018-03-13T18:42:25Z")

</div>

Effectively, it’s working. Thanks!

---

<div class="post-metadata">

**Author:** ![ybfautom](https://avatars.discourse-cdn.com/v4/letter/y/eada6e/32.png) [@ybfautom](https://forum.inductiveautomation.com/u/ybfautom)\
**Post date:** [July 3, 2019, 1:39pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/4 "2019-07-03T13:39:46Z")

</div>

Hi,  
I have a similar problem that couldn’t get solved.  
Trying to set dropdown selectedIndex property with ‘internalFrameActivated event’

Again, showing an error when the window is opened for the first time.  
Any idea on how to prevent this error?

I’m copying script and error description downwards.

Thanks for your help.

Script on Recipe window:

value = 0  
system.gui.getParentWindow(event).getComponentForPath(‘Root Container.Group1.Recipe\_Selection\_Dropdown’).selectedIndex = value

Message:

Error executing script for event: internalFrameActivated on component: Recipe.

Details:

Traceback (most recent call last):  
File “event:internalFrameActivated”, line 7, in   
java.lang.IllegalArgumentException: setSelectedIndex: 0 out of bounds  
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: setSelectedIndex: 0 out of bounds caused by IllegalArgumentException: setSelectedIndex: 0 out of bounds

Ignition v7.9.9 (b2018081621)  
Java: Oracle Corporation 1.8.0\_201

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 3, 2019, 2:40pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/5 "2019-07-03T14:40:25Z")

</div>

> [@ybfautom](#):
>
> setSelectedIndex: 0 out of bounds

Your event is running before the dropdown gets any rows in its dataset. If you deliberately want nothing selected, the selectedIndex must be set to -1, not zero.

---

<div class="post-metadata">

**Author:** ![pphillips](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@pphillips](https://forum.inductiveautomation.com/u/pphillips)\
**Post date:** [July 3, 2019, 2:46pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/6 "2019-07-03T14:46:33Z")

</div>

According to the [manual](https://docs.inductiveautomation.com/display/DOC79/Dropdown+List), .selectedIndex is a “read only” property. You should be able to set the value of .selectedValue to the .noSelectionValue to get nothing selected.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 3, 2019, 3:02pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/7 "2019-07-03T15:02:58Z")

</div>

It isn’t read-only. I write to it in code all the time. The out of bounds error is because the first row (zero) doesn’t exist.

---

<div class="post-metadata">

**Author:** ![ybfautom](https://avatars.discourse-cdn.com/v4/letter/y/eada6e/32.png) [@ybfautom](https://forum.inductiveautomation.com/u/ybfautom)\
**Post date:** [July 3, 2019, 4:05pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/8 "2019-07-03T16:05:54Z")

</div>

I’m sorry didn’t explain what I’m trying is to achive: script should select the first item on the dropdown list.  
Same error occurs if I try with index=1

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: setSelectedIndex: 1 out of bounds  
caused by IllegalArgumentException: setSelectedIndex: 1 out of bounds

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 3, 2019, 5:18pm UTC](https://forum.inductiveautomation.com/t/dropdown-selectedvalue-error-on-first-visionwindowopened/17346/9 "2019-07-03T17:18:06Z")

</div>

Sorry, what I meant is that the internalFrameActivated event is too soon. Index zero is the first row, but the first row isn’t there yet. Consider using a propertyChange event on the dropdown itself that looks for the data to arrive, selected the first row then.
