# Listbox Selected Value

**URL:** <https://forum.inductiveautomation.com/t/listbox-selected-value/780>\
**Category:** Archived Topics\
**Created:** [August 18, 2008, 1:52pm UTC](https://forum.inductiveautomation.com/t/listbox-selected-value/780 "2008-08-18T13:52:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoshMan](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@JoshMan](https://forum.inductiveautomation.com/u/JoshMan)\
**Post date:** [August 18, 2008, 1:52pm UTC](https://forum.inductiveautomation.com/t/listbox-selected-value/780/1 "2008-08-18T13:52:08Z")

</div>

I am developing a program to narrow down a selection of countries/cities/areas etc. And am doing this through listboxes. I want to design a new property that uses the selectedIndex to get the selected value or text.

Any suggestions? This is my current code.  
[code] import fpmi  
data=fpmi.db.toPyDataSet(event.source.parent.getComponent(‘StartLst’).data)

```
for item in data:
	if count==event.source.parent.getComponent('StartLst').selectedIndex:
		Root Container.StartLst.SelectedText=item[/code]
```

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [August 18, 2008, 4:51pm UTC](https://forum.inductiveautomation.com/t/listbox-selected-value/780/2 "2008-08-18T16:51:30Z")

</div>

You should not be writing a script for this. What you want to do is a databinding. Try binding your SelectedText property to an expression binding like this:

`if({Root Container.StartLst.selectedIndex} = -1,
   "-- n/a --", // Text for when nothing is selected
   {Root Container.StartLst.data}[{Root Container.StartLst.selectedIndex}, 0])`

You might want to watch the PBE (properties, bindings, and expressions) series of training videos.
