Need help overriding event in subclass

I need to use a DesktopPopupMenu with the same data in it on several windows in my app. I thought it would be more efficient to subclass PopupMenu with a method to populate it. I am running into issues with the SelectionChanged event.

The first error I got said the event was already implemented in the super class. I looked up overriding and found something that seemed to say I should add an Event Definition named SelectionChanged and a method with the same name with code that says RaiseEvent SelectionChanged. I added an instance of the subclass to a window and added code to its SelectionChanged event.

When I tried to run the app, I got an error for the event definition saying This property has the same name as an event. You must resolve this conflict. Adding a SelectionChanged Event Handler to my sub-class allows the app to compile, but nothing is passed to the instance on the window

I think I need to be adding some code to the the event definition or the event itself, but have not been able to figure out what it should be. I remember doing something like this several years ago, but don’t remember having this much trouble. An example that shows how to do this would be wonderful.

Looks like you figured out all the parts but not how to use them :slightly_smiling_face:

In the subclass’ SelectionChanged event add this code:

RaiseEvent SelectionChanged

That will enable you to have some shared code when changing the selection of the popup menu, and still do something else in each instance.

Although I’m not sure that is what you are really looking for.
To populate the PopupMenu, it should be done in the Opening event.

Thanks for the help. I had the code right, but in the wrong place.

The popup is populated from from a method instead the opening because I want it to update if the user changes anything in the database.