PopupMenu in Container Control - LastAddedRowIndex Bug

I have a PopupMenu that is placed in a container control which I’m embedding via code.
If the container is embedded before items are added to the PopupMenu, then LastAddedRowIndex returns the correct value, but if the items are added before embedding the container, then LastAddedRowIndex is always -1.

Is this a bug or expected behavior? The results are the same with a PopupMenu or a DesktopPopupMenu.

It’s also odd that the popup that has items added before embedding will auto-select row index 0 while the popup that has its items added after embedding will have row index -1 selected.

The row selection is not too significant, but the LastAddedRowIndex is problematic if you’re trying to add row tags along with the values.

I don’t know if it’s “expected” or not, but I’ve run into the same thing with ListBox. Any content added to the control prior to embedding is “lost”, i.e. unavailable after embedding, but no errors are generated.

It certainly sounds wrong. Likely worth opening an issue for it.

The pointed behavior makes me think that EmbedWithin works for Containers as kind of New works for Classes, the “instance” happens after its use, and contents are initialized, so changes to instance are only possible after that. The bad news is that Xojo lets changes before that and the silent fails it brings with it “initializing” contents (AGAIN?) with the embedding.

Xojo should see what they can do about to avoid such silent fails.

1 Like

To be honest, i’d expect it to be -1 after the control has been instantiated. :man_shrugging:

It feels to me that the items either shouldn’t be added at all if the container isn’t embedded or the LastAddedRowIndex should be correct.

It’s successfully adding rows, but not tracking the last added index.

I’ll submit it as a bug.

a small example
for character set and popup

https://www.dropbox.com/s/ce8j7dd114zhpl4/Mypopup-neu-ok.xojo_binary_project?dl=1