Drop down refresh

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


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

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

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…

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

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.

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()

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