Dumb RowTag question.

I’ve populated a PopUpMenu with customer names and the RowTags with their DB account ids (such as 9, 213, 1764 etc…)

How do I now set the selected item of the PopUpMenu from the account id? So I want to do something like

PopUpMenu.ListIndex = (the one where the rowtag =213)

I’m sure this is something insanely simple that I’ve done before but I’m just stuck…

You have to loop through all the items to find the RowTag you want, once you do you set the PopupMenu.ListIndex

Oh OK thanks. I thought there might be a slicker method I was missing!

You could create a dictionary in parallel
The key is the rowtag.
The value is the actual row number.

Seek the rowtag from the dictionary, set the listindex to match.

You could sublass the listbox - add the dictionary to it as a property , append to the dictionary when you add a row, and then call a method to SetIndexByTag()

Don’t forget that you’d have to update when you delete, sort or drag reorder as well.

For all the necessary work to maintain the dictionary, I’d just stick with looping through the rows.

The looping method worked just fine so I’ll stick to that and move on!

Interesting idea though Jeff. I may have a fiddle with that just out of curiosity as I’ve not used dictionaries yet and it will be a good exercise.