Let’s say that I have 3 items in a ComboBox, and they’re all named the same “The item”. Only thing that separates them is item ID (which is not persistent) and section heading:
The item <- ticked!
Now, I want to persist the selection. Only way to do that is to save “Heading 3” + “The Item”. But currently there is no way to get the section heading from the ComboBox via id or index. So I’d like a getSectionHeader(const int itemIndex) and getSectionHeaderFromId(const int itemId).
That way I can get which one should be selected when loading my “document” again.
You should think of the combo box’s item list as a write-only object… Store your list of items somewhere else, in whatever format makes sense for your app, and add use that to refresh the combo box’s items when necessary. It’s very bad form to use a UI component as a way of storing your program’s state!
(In fact, rather than making me want to add an accessor method for you, your post has actually just made me want to go in there and remove all the existing accessor methods to stop it being used like this!)
Sorry, maybe I haven’t been clear enough. I’m not using it to store the state, but when I do restore the state, I want to make sure the correct entry in the combo box is selected. But you’re right though that that can be done otherwise.
Sorry, maybe I’m being a bit dim, but I’m obviously still failing to understand what you mean!
You’re adding a bunch of items to the combobox, and you know the ID of the one that should be ticked, right? Surely calling setSelectedItemID will tick the correct one, even when you have duplicate strings (??)