ListView MouseUp Event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Bean

    ListView MouseUp Event

    I am trying to display a ContextMenuStri p when a user right-clicks on an
    item in a ListView and have encountered a something that seems strange to
    me.

    When the ListView is initially populated, no items are selected. When the
    first item is selected by clicking either the left or right button, the
    SelectedIndexCh anged event fires but not the MouseUp event. After the first
    item is selected and another item clicked on, both the SelectedIndexCh anged
    and MouseUp events fire.

    Since I am calling Show() for the context menu in the MouseUp event when the
    right button is clicked, no context menu is displayed when the first
    selection is made by right-clicking an item.

    Can anyone tell me if it is normal behavior for the MouseUp event not to
    fire when the first selection is made? Is there any way to ensure the
    context menu is displayed for the first selection?

    Thanks,
    Tom


  • zacks@construction-imaging.com

    #2
    Re: ListView MouseUp Event

    On Apr 8, 3:21 pm, "Tom Bean" <tb...@newsgrou p.nospamwrote:
    I am trying to display a ContextMenuStri p when a user right-clicks on an
    item in a ListView and have encountered a something that seems strange to
    me.
    >
    When the ListView is initially populated, no items are selected.  When the
    first item is selected by clicking either the left or right button, the
    SelectedIndexCh anged event fires but not the MouseUp event.  After the first
    item is selected and another item clicked on, both the SelectedIndexCh anged
    and MouseUp events fire.
    >
    Since I am calling Show() for the context menu in the MouseUp event when the
    right button is clicked, no context menu is displayed when the first
    selection is made by right-clicking an item.
    >
    Can anyone tell me if it is normal behavior for the MouseUp event not to
    fire when the first selection is made?  Is there any way to ensure the
    context menu is displayed for the first selection?
    I cannot qanswer your question about the MouseUp event, but I am
    wondering how come you are not using the "buildt in" method of showing
    a context menu by setting the ListView's ContextMenu property?

    Comment

    • Tom Bean

      #3
      Re: ListView MouseUp Event

      Quite frankly, I probably used the MouseUp event to show the the context
      menu in some special case and just got in the habit of using it.

      There is one notable difference between the way the context menu is shown
      when the listview property is set and the way it shows using the MouseUp
      event. When I removed the MouseUp event handler and let the listview show
      the context menu, the context menu only appears when an item is selected
      with a mouse button click and then the selected item is right-clicked. In
      other words, it always behaves the way it does when the first item is
      selected by a right-click. At least, letting the listview handle the context
      menu offers consistent behavior.

      <zacks@construc tion-imaging.comwrot e in message
      news:4ecae032-1cf0-433e-bab0-6713171eb919@a7 0g2000hsh.googl egroups.com...
      On Apr 8, 3:21 pm, "Tom Bean" <tb...@newsgrou p.nospamwrote:
      I am trying to display a ContextMenuStri p when a user right-clicks on an
      item in a ListView and have encountered a something that seems strange to
      me.
      >
      When the ListView is initially populated, no items are selected. When the
      first item is selected by clicking either the left or right button, the
      SelectedIndexCh anged event fires but not the MouseUp event. After the
      first
      item is selected and another item clicked on, both the
      SelectedIndexCh anged
      and MouseUp events fire.
      >
      Since I am calling Show() for the context menu in the MouseUp event when
      the
      right button is clicked, no context menu is displayed when the first
      selection is made by right-clicking an item.
      >
      Can anyone tell me if it is normal behavior for the MouseUp event not to
      fire when the first selection is made? Is there any way to ensure the
      context menu is displayed for the first selection?
      I cannot qanswer your question about the MouseUp event, but I am
      wondering how come you are not using the "buildt in" method of showing
      a context menu by setting the ListView's ContextMenu property?


      Comment

      • Linda Liu[MSFT]

        #4
        Re: ListView MouseUp Event

        Hi Tom,

        Thank you for your prompt reply!

        I performed another test in VS2008, version 9.0.21022.8 RTM, but still
        didn't reproduce the problem.

        What's the OS version on which you run the application? You may have a try
        running the application on another machine to see if the problem still
        exists.

        Sincerely,
        Linda Liu
        Microsoft Online Community Support

        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.

        This posting is provided "AS IS" with no warranties, and confers no rights.


        Comment

        • Tom Bean

          #5
          Re: ListView MouseUp Event

          Linda,

          I'm running Windows XP Professional SP2 but if this is OS related, I can't
          really test on another system because they are all running the same OS.

          Thanks,
          Tom

          "Linda Liu[MSFT]" <v-lliu@online.mic rosoft.comwrote in message
          news:W7J0Z%23um IHA.10116@TK2MS FTNGHUB02.phx.g bl...
          Hi Tom,
          >
          Thank you for your prompt reply!
          >
          I performed another test in VS2008, version 9.0.21022.8 RTM, but still
          didn't reproduce the problem.
          >
          What's the OS version on which you run the application? You may have a try
          running the application on another machine to see if the problem still
          exists.
          >
          Sincerely,
          Linda Liu
          Microsoft Online Community Support
          >
          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.
          >
          This posting is provided "AS IS" with no warranties, and confers no
          rights.
          >
          >

          Comment

          • Linda Liu[MSFT]

            #6
            Re: ListView MouseUp Event

            Hi Tom,

            Thank you for your quick reply!

            I have performed tests on Windows XP Professional SP2, but didn't reproduce
            the problem on it.

            If you handle the ListView's MouseDown event instead of the MouseUp event,
            does the problem still exist?

            Sincerely,
            Linda Liu
            Microsoft Online Community Support

            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            This posting is provided "AS IS" with no warranties, and confers no rights.


            Comment

            • Tom Bean

              #7
              Re: ListView MouseUp Event

              Linda,

              I had set the ContextMenuStri p property for the ListView and was also trying
              to open the context menu in the MouseUp event handler. I thought these two
              methods might be interferring with one another so I tried them one at a
              time.

              First, I tried commenting out the MouseUp event handler and letting the
              ListView handle the context menu as was suggested in zacks' reply to my
              initial post and the behavior I see is:
              1) a right-click on an unselected item only selects it (no context menu
              opens)
              2) a right-click on a selected item opens the context menu.

              This happens consistently. Is this the expected behavior?

              Next, I tried only handling the context menu with the MouseUp event and a
              right-click on a selected item opens the context menu, however, after
              selecting another item and left-clicking on the previously selected item,
              sometimes the context menu opened. It is like one or more MouseUp events
              were being handled out of sequence.

              In my application, when an item is selected in the ListView, data is
              retrieved from a database and used to populate various controls on the
              UserControl which causes focus to be removed from the ListView. Could this
              cause the mouse events to be sent to the other controls, thereby, causing
              the mouse events to be out of sequence?

              If so, would the problem be resolved by setting the focus back to the
              ListView after populating the other controls?

              Thanks,
              Tom

              "Linda Liu[MSFT]" <v-lliu@online.mic rosoft.comwrote in message
              news:hLVrZk6mIH A.8872@TK2MSFTN GHUB02.phx.gbl. ..
              Hi Tom,
              >
              Thank you for your quick reply!
              >
              I have performed tests on Windows XP Professional SP2, but didn't
              reproduce
              the problem on it.
              >
              If you handle the ListView's MouseDown event instead of the MouseUp event,
              does the problem still exist?
              >
              Sincerely,
              Linda Liu
              Microsoft Online Community Support
              >
              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.
              >
              This posting is provided "AS IS" with no warranties, and confers no
              rights.
              >
              >

              Comment

              • Tom Bean

                #8
                Re: ListView MouseUp Event

                Linda,

                I had set the ContextMenuStri p property for the ListView and was also trying
                to open the context menu in the MouseUp event handler. I thought these two
                methods might be interferring with one another so I tried them one at a
                time.

                First, I tried commenting out the MouseUp event handler and letting the
                ListView handle the context menu as was suggested in zacks' reply to my
                initial post and the behavior I see is:
                1) a right-click on an unselected item only selects it (no context menu
                opens)
                2) a right-click on a selected item opens the context menu.

                This happens consistently. Is this the expected behavior?

                Next, I tried only handling the context menu with the MouseUp event and a
                right-click on a selected item opens the context menu, however, after
                selecting another item and left-clicking on the previously selected item,
                sometimes the context menu opened. It is like one or more MouseUp events
                were being handled out of sequence.

                In my application, when an item is selected in the ListView, data is
                retrieved from a database and used to populate various controls on the
                UserControl which causes focus to be removed from the ListView. Could this
                cause the mouse events to be sent to the other controls, thereby, causing
                the mouse events to be out of sequence?

                If so, would the problem be resolved by setting the focus back to the
                ListView after populating the other controls?

                Thanks,
                Tom

                "Linda Liu[MSFT]" <v-lliu@online.mic rosoft.comwrote in message
                news:hLVrZk6mIH A.8872@TK2MSFTN GHUB02.phx.gbl. ..
                Hi Tom,
                >
                Thank you for your quick reply!
                >
                I have performed tests on Windows XP Professional SP2, but didn't
                reproduce
                the problem on it.
                >
                If you handle the ListView's MouseDown event instead of the MouseUp event,
                does the problem still exist?
                >
                Sincerely,
                Linda Liu
                Microsoft Online Community Support
                >
                Delighting our customers is our #1 priority. We welcome your comments and
                suggestions about how we can improve the support we provide to you. Please
                feel free to let my manager know what you think of the level of service
                provided. You can send feedback directly to my manager at:
                msdnmg@microsof t.com.
                >
                This posting is provided "AS IS" with no warranties, and confers no
                rights.
                >
                >

                Comment

                • Linda Liu[MSFT]

                  #9
                  Re: ListView MouseUp Event

                  Hi Tom,

                  Thank you for your quick response and detailed information!
                  This happens consistently. Is this the expected behavior?
                  I didn't reproduce this problem on my side. Every time I right-click on an
                  unselected or selected item, the context menu is always opened.
                  If so, would the problem be resolved by setting the focus back to the
                  ListView after populating the other controls?

                  It would be better if you could send me a simple project that could
                  reproduce the problem you describe. To get my actual email address, remove
                  'online' from my displayed email address.

                  Sincerely,
                  Linda Liu
                  Microsoft Online Community Support

                  Delighting our customers is our #1 priority. We welcome your comments and
                  suggestions about how we can improve the support we provide to you. Please
                  feel free to let my manager know what you think of the level of service
                  provided. You can send feedback directly to my manager at:
                  msdnmg@microsof t.com.

                  This posting is provided "AS IS" with no warranties, and confers no rights.


                  Comment

                  • Tom Bean

                    #10
                    Re: ListView MouseUp Event

                    Linda,

                    This is the same user control we corresponded about after my post on 3/24.
                    I could never get drag & drop to work properly and this problem is regarding
                    implementing copy/paste via a context menu to replace the drag & drop.

                    I am convinced there is too much going on when an item is selected, e.g.
                    retrieving data from SQL Server, populating controls... This is compounded
                    by the fact that my list view is instantiated from derived ListView class to
                    extend the ListView functionality.

                    I never could get the context menu to open with a single right-click when I
                    set the ContextMenuStri p property of the list view, however, it is working
                    now with the MouseUp event handler. Frankly, I changed so many things I'm
                    not sure what finally got it working.

                    Thanks for your help.

                    Tom

                    "Linda Liu[MSFT]" <v-lliu@online.mic rosoft.comwrote in message
                    news:t0sCcxgnIH A.8872@TK2MSFTN GHUB02.phx.gbl. ..
                    Hi Tom,
                    >
                    Thank you for your quick response and detailed information!
                    >
                    >This happens consistently. Is this the expected behavior?
                    I didn't reproduce this problem on my side. Every time I right-click on an
                    unselected or selected item, the context menu is always opened.
                    >
                    >If so, would the problem be resolved by setting the focus back to the
                    ListView after populating the other controls?
                    >
                    It would be better if you could send me a simple project that could
                    reproduce the problem you describe. To get my actual email address, remove
                    'online' from my displayed email address.
                    >
                    Sincerely,
                    Linda Liu
                    Microsoft Online Community Support
                    >
                    Delighting our customers is our #1 priority. We welcome your comments and
                    suggestions about how we can improve the support we provide to you. Please
                    feel free to let my manager know what you think of the level of service
                    provided. You can send feedback directly to my manager at:
                    msdnmg@microsof t.com.
                    >
                    This posting is provided "AS IS" with no warranties, and confers no
                    rights.
                    >
                    >

                    Comment

                    • Linda Liu[MSFT]

                      #11
                      Re: ListView MouseUp Event

                      Hi Tom,

                      Thank you for your prompt reply!

                      Do you mean that you have made some changes in your project and the problem
                      disappears finally?

                      If the problem appears again or you still need our assistance, please feel
                      free to let me know.

                      Thank you for using our MSDN Managed Newsgroup Support Service!

                      Sincerely,
                      Linda Liu
                      Microsoft Online Community Support

                      Delighting our customers is our #1 priority. We welcome your comments and
                      suggestions about how we can improve the support we provide to you. Please
                      feel free to let my manager know what you think of the level of service
                      provided. You can send feedback directly to my manager at:
                      msdnmg@microsof t.com.

                      This posting is provided "AS IS" with no warranties, and confers no rights.


                      Comment

                      • Tom Bean

                        #12
                        Re: ListView MouseUp Event

                        Linda,

                        Yes, the context menu seems to be working now. I'm not really sure why but
                        it's good enough for now.

                        Thanks,
                        Tom

                        "Linda Liu[MSFT]" <v-lliu@online.mic rosoft.comwrote in message
                        news:gvB1KQqnIH A.4932@TK2MSFTN GHUB02.phx.gbl. ..
                        Hi Tom,
                        >
                        Thank you for your prompt reply!
                        >
                        Do you mean that you have made some changes in your project and the
                        problem
                        disappears finally?
                        >
                        If the problem appears again or you still need our assistance, please feel
                        free to let me know.
                        >
                        Thank you for using our MSDN Managed Newsgroup Support Service!
                        >
                        Sincerely,
                        Linda Liu
                        Microsoft Online Community Support
                        >
                        Delighting our customers is our #1 priority. We welcome your comments and
                        suggestions about how we can improve the support we provide to you. Please
                        feel free to let my manager know what you think of the level of service
                        provided. You can send feedback directly to my manager at:
                        msdnmg@microsof t.com.
                        >
                        This posting is provided "AS IS" with no warranties, and confers no
                        rights.
                        >
                        >

                        Comment

                        • Linda Liu[MSFT]

                          #13
                          Re: ListView MouseUp Event

                          Hi Tom,

                          Thank you for your response!

                          I will close this issue since the problem disappears now. But if the
                          problem appears later, please feel free to reopen this issue and I will
                          continute to work with you.

                          Thank you for using our MSDN Managed Newsgroup Support Service!

                          Sincerely,
                          Linda Liu
                          Microsoft Online Community Support

                          Delighting our customers is our #1 priority. We welcome your comments and
                          suggestions about how we can improve the support we provide to you. Please
                          feel free to let my manager know what you think of the level of service
                          provided. You can send feedback directly to my manager at:
                          msdnmg@microsof t.com.

                          This posting is provided "AS IS" with no warranties, and confers no rights.


                          Comment

                          Working...