Search code examples
c#listviewcontextmenumousedown

Context Menu - How can I know which control activated it


I have made a context menu which is activated via MouseDownevent. This event checks if the user clicked the right button and if so opens the menu. I am using the same event to open the same context menu for a listbox and a listview. Is there a way to check which one of them activated the MouseDown event?

Edit: I'll be a bit more specific. I can tell which controller activated the event from the event itself.. I want to know which controller activated the event from the context menu item which has been clicked on.


Solution

  • I solved it by using the Tag property of the context menu. I put there the sender object which triggered the event, and then I could just do:

    ListView lv = resultsContextMenu.Tag as ListView;
    if (lv == null) //listbox was the one to call the mouse down event
    { //do stuff }
    

    this code was called inside the menu items themselves that were chosen by the user