I have a tuple as a value in a drop down. So, items looks like this :
[
("Hello", (5,"Hello"))
]
I want to programmatically set the selected value (as a default) like this :
self.dropdown.selected_value = 5
but that doesn’t work. I need the value to be a tuple as I need access to the drop down text of the selection.
Is it possible?
This would do it:
self.dropdown.selected_value = (5,"Hello")
(Or a for
loop to go through self.dropdown.items
and find the right one.)
That said, if I found myself doing this I might try to organise things differently. What are you trying to do?
One of the items will have an ID of zero, and I always want that one to be the default selected value when the form loads. Unfortunately I won’t know what the text is in advance.
I may not be seeing the issue clearly, but if I use lists I can change the value as expected.
self.drop_down_1.items=[["Hello", [5,"Hello"]]]
self.drop_down_1.selected_value[0]=10
print(self.drop_down_1.selected_value[0])
#returns 10
Here’s what I would do:
for name, (number,_) in self.dropdown.items:
if number == 0:
self.dropdown.selected_value = (number,name)
2 Likes
That’s the missing link for me 
Ta muchly.
Oh, and I agree I might need to structure some of this, I just need to get something out of the door today and that was the only thing holding me back…