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.
The windowOpened event is documented to run before bindings for the window. You probably want to use internalFrameOpened or internalFrameActivated instead. (See the notes in the docs.)
Effectively, it’s working. Thanks!
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
Error executing script for event: internalFrameActivated on component: Recipe.
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
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.
According to the manual, .selectedIndex is a “read only” property. You should be able to set the value of .selectedValue to the .noSelectionValue to get nothing selected.
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.
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
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.