ComboBox request

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:

    Heading 1
        The item
    Heading 2
        The item
    Heading 3
        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.

TIA
/Rob

But if you want to persist this info, you should be doing it in your data model, not by relying on a UI component to provide the state for you, right…?

Well, I thought I’d take the easy way. But anyway, the request isn’t too off is it ? :wink: Since items can be grouped by section headers, isn’t it reasonable to get the header for a specific item ?

No, that doesn’t follow at all!

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.

Ok, calm down, will ya ? :wink:

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

For sure, that is how I do it, just had a mind lapse there I guess. Don’t know what I was thinking about…