Setting the default value of a list programacilly

I have a script that populates a few list boxes, how can I have it set the listbox to select the first item in the list.

Can anyone point me in the right direction? Thanks

Could you post the script? I can think of a couple ways to do this.
If you are doing a For loop you could just nest an additional layer to execute on the first pass of the loop and set the component ‘Selected Value’ property to the correct index number.

Thanks for the reply,

The dataset is pulling from a text file and is populating the list properly.

This is what populates the list, Matches is returned from a function

#populate the listbox with the matches event.source.parent.parent.getComponent('ListID').data = Matches

The list populates fine, i was just unsure how to select the first item in the list, I tried out a few things without success. All I have left that didnt fail is below.

I was attempting to select the first item with

#select the first item in LotID ListLot = event.source.parent.parent.getComponent('ListID')

Any help/suggestions are welcome! Thanks

By list are you talking about the dropdown list component? If so - you just need to set the selectedIndex property.

event.source.parent.getComponent('Dropdown').selectedIndex = 2

event.source.parent.parent.getComponent(‘ListID’).selectedIndex = 0

Hi Guys, Its not a dropdown list, its a List from the Table section in the component Palette. I added the code listed below, which is what I tried already and nothing gets selected but nothing fails either.

When i return the value of the selected item it gives me 0, the selected item specified.

SelectedItem = event.source.parent.parent.getComponent('ListID').selectedIndex = 0
print SelectedItem # returns 0

Would it be easier if I could return the value of the selection for verification? How can i incorporate the selected item with its value?

I tried this but it did not work

Items = event.source.parent.parent.getComponent('ListID') Valued = Items.getValueAt(event.source.selectedIndex,0) print Valued

I’m still not sure how to incorporate getValueAt, i couuldnt find it in the docs, Thanks

We must be missing a piece of the puzzle here… because setting the selectedIndex property on the List component works just fine for me.

Can you post all of your script and a little bit more about where it runs from and when it runs?

Hi Kevin,

The code you posted is correct, i feel stupid but I must not have saved before I ran the script.

But now I have another question, how can i get the selected value of the selected item? It does get tricky for me as I have two list boxes, one populates based on what was selected from the first.

So, you select the list box on the left (Which Ill call L1), the list box on the right (which Ill call L2) populates and the first item is selected. I then set that selected value to a tag. Right now the tag is not being set but L2 is selecting the first item.

Im still new with ignition and using the event syntax to select L2 not seem to work right as the event is being generated from L1. Any suggestions

Thanks again for all the help

The list component uses getSelectedValue() to return a value for a singular selected item, or getSelectedValues() to return a list of multiple selected items.

list = event.source.parent.parent.getComponent(‘ListID’)
if not list.isSelectionEmpty():
data = list.getSelectedValue()

Thanks Mark,

That works great! I have another question, my dataset for the list has two columns. When the selected value is returned, i get the text displayed. How can I get the second column of data in the dataset, the one not displayed in the list? I tried data[1] but that didn’t work. thanks!

This will get the second column, it is column index 1
col2data = list.data.getValueAt(list.selectedIndex,1)

That did the trick, your the man! Thanks