Determine Control that initiated a ContextMenuStrip?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • horizon
    New Member
    • Jan 2008
    • 13

    #1

    Determine Control that initiated a ContextMenuStrip?

    I have a single ContextMenuStri p (with a single menu item) associated with two ListViews, How do I determine which of the two ListViews the menu event occured on?

    I could probably find the control through coordinates, but is there an "Object" variable somewhere holding this information?
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    The events that fire should have a sender object?

    Comment

    • horizon
      New Member
      • Jan 2008
      • 13

      #3
      Originally posted by Plater
      The events that fire should have a sender object?
      The sender object only returns the menuitem object, I need to know which of the two listview had the menuitem executed over, so I can perform seperate actions depending on the listview the user selected the menu over.

      I'll state it again the contextMenuStri p has only one menuitem assigned to it

      > "Refresh"

      and to it I have the following on click event assigned

      private void refreshListTool StripMenuItem_C lick(object sender, EventArgs e)
      {
      !!! sender == refreshListTool StripMenuItem !!!
      }

      I just need to know which listview to refersh, very simple although .NET is making it very difficult, should probably just create two identical contextMenuStri p and get it over and done with instead of troubling you guys.

      And thanks Plater for taking the time to reply.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well ok, an event is fired when the menu itself is shown on the listbox (so in that you could have a variable keep track of the sender)

        So attach a listener for each listbox to the event. In the event say like:
        lastsender=send er;

        And be sure to have lastsender originaly declared outside the event handlers so each of them can see it.

        Then in your menu items event you can look at the last sender variable and refresh them?

        Comment

        • horizon
          New Member
          • Jan 2008
          • 13

          #5
          Originally posted by Plater
          Well ok, an event is fired when the menu itself is shown on the listbox (so in that you could have a variable keep track of the sender)

          So attach a listener for each listbox to the event. In the event say like:
          lastsender=send er;

          And be sure to have lastsender originaly declared outside the event handlers so each of them can see it.

          Then in your menu items event you can look at the last sender variable and refresh them?
          Ok so answering my first post, "there is no such object", unless creating custom flags/switches?, so like I said I'll just create two separate but identical contextMenus and call it a day!

          Thanks once again Plater for your help... it's just a shame that whatever strong points .NET has to offer it's still lacking in very simple and expected behavior found within other languages, here's another fine example with listview's and listbox's missing a very crucial SelectedIndexChanging event... nough said thanks again.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Both the Listbox and the ListView contain selectedindexch anging events. They clearly show up in my visual studio at least?

            Comment

            • horizon
              New Member
              • Jan 2008
              • 13

              #7
              Ok so I never mentioned that I was just using a normal c# windows project (on Windows XP), from what I gather only asp .net offers access to the selectedindexch anging event property.

              Unless your confusing "SelectedIn dexChanged" <<with>> "SelectedIn dexChanging" or have built your own listview wraper I can't see how you could possibly access that event within a standard windows project. Would you care to provide an example?

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Ah yes, I was confusing changed with changing.
                But now I cannot fathom why you would need to know about "changing" over "changed"?

                What use does it offer you?

                Comment

                • horizon
                  New Member
                  • Jan 2008
                  • 13

                  #9
                  Doesn't notpad.exe prompt you whether you'd like to save an edited file before closing notepad or even cancel the exit command altogether? same thing!

                  If I had a list of files within a listview, and somewhere else on the form I allowed data input associated with that selected file in the listview, wouldn't it be appropriated to alert the user attempting to select another file if they'd like to save any modified data first or cancel (ie; stay put on the same listview selected item)?

                  Anyway I know this is all off-topic from my original question so I'd better leave it here for now and thanks for showing interest in my petty problems Plater, if I have any further questions regarding this I'll follow up within another thread in case others are having the same difficulties as I am.

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    Well I am still confused. Notepad notes change of state (which would change of index) not changing of state. Regardless, now I've forgotten. Was your original problem solved?

                    Comment

                    Working...