# Drop down refresh

**URL:** <https://forum.inductiveautomation.com/t/drop-down-refresh/9120>\
**Category:** General Discussion\
**Created:** [September 30, 2014, 4:33pm UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120 "2014-09-30T16:33:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricFrancoeur](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@EricFrancoeur](https://forum.inductiveautomation.com/u/EricFrancoeur)\
**Post date:** [September 30, 2014, 4:33pm UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120/1 "2014-09-30T16:33:10Z")

</div>

Hello, I have a dropdown that takes it’s data from an MySQL query. It’s a list of preset value an when selected it fills the form. No biggie there.

What I also have on that for is a save button in case I change values on that form and want to keep it as preset and then refresh my dropdown query so that the new preset is in…

My problem is that when I save my SELECTED dropdown goes back to its last value instead of the new preset one, hense swapping all values from the form to the last preset values.

I would like after the refresh, my new preset would be selected in the dropbox.

Here is where I am so far

```auto

qryCreateTickets = """INSERT INTO tblpresetLotPalette
				(strDimension, strCommentaire, strEssence, strGrade, intPieces, intTE,
				 strTF, intWE, strWF, intLE, strLF)
				 VALUES (?,?,?,?,?,?,?,?,?,?,?)
			"""
##Dimension is the name of the preset and everything else is an attribute			
system.db.runPrepUpdate(qryCreateTickets, [Dimension, Commentaire, Essence, Grade, Pieces,TE, TF, WE, WF, LE, LF])	
		
##Refresh the dropdown data
system.db.refresh(event.source.parent.parent.getComponent('Dropdown'), "data")
		
##Here's the problem, I can't force the dropdown to take the string Dimension(The name of the new preset) as it's selected
event.source.parent.parent.getComponent('Dropdown').selectedStringValue = Dimension

```

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [October 6, 2014, 4:38am UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120/2 "2014-10-06T04:38:40Z")

</div>

An INSERT query does not change data in a database, it adds new data. Maybe what you need is an UPDATE query.

---

<div class="post-metadata">

**Author:** ![EricFrancoeur](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@EricFrancoeur](https://forum.inductiveautomation.com/u/EricFrancoeur)\
**Post date:** [October 7, 2014, 4:32pm UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120/3 "2014-10-07T16:32:47Z")

</div>

My question isn’t related to the database, that part works fine. My problem is when I refresh my dropdown, its selected value is not the saved dimension but the previous saved one…

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [October 7, 2014, 5:58pm UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120/4 "2014-10-07T17:58:13Z")

</div>

If the drop down is directly bound to a MySQL query I would think that it is possible that this code:

```auto
event.source.parent.parent.getComponent('Dropdown').selectedStringValue = Dimension
```

is being evaluated before the drop down data set is updated.

I would try moving the code above into the property change event (event.propertyName == “data”) for the drop down.

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://forum.inductiveautomation.com/u/Robert)\
**Post date:** [October 7, 2014, 6:01pm UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120/5 "2014-10-07T18:01:53Z")

</div>

I think you need to update the dropdown in a separate thread.

What I think is happen is you are updating the selected value, but it’s getting overwritten by the form update that is cause by pushing the save button.

things to check: do you have anything on the form that updates automatically when a property changes?

read up on system.util.invokeLater()

---

<div class="post-metadata">

**Author:** ![EricFrancoeur](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@EricFrancoeur](https://forum.inductiveautomation.com/u/EricFrancoeur)\
**Post date:** [February 3, 2015, 1:31pm UTC](https://forum.inductiveautomation.com/t/drop-down-refresh/9120/6 "2015-02-03T13:31:15Z")

</div>

Well my fix is quite stupid… I’ve put a messageBox between the refresh and the change propriety line that says save completed. The time the user clicks the OK button it’s enough for the refresh to finish…

I know it’s an extra step, but they’ll use that button 20 times a year… so no biggie there in my case
