populating popup menus, listboxes, inefficient coding

Hey everybody. I just realized (once more) how lame my coding is…

The situation :

I have one listbox and three popup menus which I use to filter the results shown in that listbox.

Populating the menus is done programmatically as these menus appear many times in my app with different amount of entries.

The conflict :

As this menus are used as dinamic filters for the listbox, every time the selection in one of these popupmenus is changed, the listbox is updated. I am using the change event handler, to update the listbox.

This means, that every time a new entry is added to the each menu while being populated, the listbox itself is populated again, as the change event handler is triggered.
Each menu may have 6-7 entries, so the listbox is filled maybe 20 times in a row… Talking about waste of resources… That databse wants to kill me.

What better options do I have ?

Thanks for the feedback.

I suppose the change event is owned by the PopupMenu.

How do you update the Listbox ?

Do you delete the Listbox contents and rebuild it or do you only append a new Row to the Listbox ?

You know when you update the menu, so introduce a guard variable in the PopupMenu:

// In MyPopupMenu: Event Change() If IsUpdating Then Return // do nothing End // Update the listbox here End

MyPopupMenu.IsUpdating = True // Update the popup menu MyPopupMenu.IsUpdating = False

before you update, set popup.enabled = false

then in your fill code

if not popup.enabled then fillList

Hey Emile, you are right. The change event is owned by the PopupMenu.

The update of the list box is done by a method called on PopupMenu change.