Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Handling Click and DoubleClick events differently

Handling Click and DoubleClick events differently

Scheduled Pinned Locked Moved C#
csharpdelphivisual-studiodesignperformance
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dr Walt Fair PE

    I have an application that I'm converting to C# and have run into a problem. If I overlooked the discussion of this elsewhere, I apologize in advance. Here's the situation: I have a list box with various items in it. When I click on one, I want it to select the item and highlight the equivalent info on another control - that works perfectly. When I doubleclick, I want it to open a dialog allowing the item to be edited, displayed in detail or something similar. Unfortunately, even though both events are active and coded, the single click event always fires, no matter how fast one doubleclicks. In order to get the double click to work, I have to click 3 times and the single click event always fires first. I know one option would be to change the UI, but this is a mature (but non.NET) application and users want the same click vs. double click performance, so changing the behavior is a last resort and not really a good option. Is there something I'm doing wrong? Is there a workaround? BTW, the equivalent code works perfectly in the old app, which was written in Delphi. Any suggestions or insights would be very much appreciated!

    The PetroNerd

    Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

    V Offline
    V Offline
    Vikram A Punathambekar
    wrote on last edited by
    #2

    I remember reading a while back that a double click action should always be an 'add on' to a single click. Eg: In Explorer, single click selects a folder/file; double click selects it and then opens it. I suppose you could spin off a thread in your single click handler that waits to see if a double click event is fired, and if not, does its work. I am almost certain that would turn out to be very ugly. Long story short - if your double click action differs significantly, it's better off as a right click option.

    Cheers, Vikram.


    The hands that help are holier than the lips that pray.

    D 1 Reply Last reply
    0
    • D Dr Walt Fair PE

      I have an application that I'm converting to C# and have run into a problem. If I overlooked the discussion of this elsewhere, I apologize in advance. Here's the situation: I have a list box with various items in it. When I click on one, I want it to select the item and highlight the equivalent info on another control - that works perfectly. When I doubleclick, I want it to open a dialog allowing the item to be edited, displayed in detail or something similar. Unfortunately, even though both events are active and coded, the single click event always fires, no matter how fast one doubleclicks. In order to get the double click to work, I have to click 3 times and the single click event always fires first. I know one option would be to change the UI, but this is a mature (but non.NET) application and users want the same click vs. double click performance, so changing the behavior is a last resort and not really a good option. Is there something I'm doing wrong? Is there a workaround? BTW, the equivalent code works perfectly in the old app, which was written in Delphi. Any suggestions or insights would be very much appreciated!

      The PetroNerd

      Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

      A Offline
      A Offline
      Atif Ali Bhatti
      wrote on last edited by
      #3

      Assalam-0-Alaikum Are you willing to do it on ClientSide or ServerSide? Regards. Atif Ali Bhatti.

      V D 2 Replies Last reply
      0
      • A Atif Ali Bhatti

        Assalam-0-Alaikum Are you willing to do it on ClientSide or ServerSide? Regards. Atif Ali Bhatti.

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #4

        Alaikum Assalam. He is talking about a Winforms app.

        Cheers, Vikram.


        The hands that help are holier than the lips that pray.

        A 1 Reply Last reply
        0
        • V Vikram A Punathambekar

          Alaikum Assalam. He is talking about a Winforms app.

          Cheers, Vikram.


          The hands that help are holier than the lips that pray.

          A Offline
          A Offline
          Atif Ali Bhatti
          wrote on last edited by
          #5

          OK. Following links can help u out. This one is Excellent and easy, http://msdn.microsoft.com/en-us/library/ms171543(VS.80).aspx[^] this one is also good. http://www.megasolutions.net/cSharp/Click-vs-DoubleClick-44615.aspx[^] Hope this solves your problem. Regards. Atif Ali Bhatti.

          D 1 Reply Last reply
          0
          • A Atif Ali Bhatti

            Assalam-0-Alaikum Are you willing to do it on ClientSide or ServerSide? Regards. Atif Ali Bhatti.

            D Offline
            D Offline
            Dr Walt Fair PE
            wrote on last edited by
            #6

            Actually it's a desktop app, no client or server involved.

            The PetroNerd

            Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

            1 Reply Last reply
            0
            • V Vikram A Punathambekar

              I remember reading a while back that a double click action should always be an 'add on' to a single click. Eg: In Explorer, single click selects a folder/file; double click selects it and then opens it. I suppose you could spin off a thread in your single click handler that waits to see if a double click event is fired, and if not, does its work. I am almost certain that would turn out to be very ugly. Long story short - if your double click action differs significantly, it's better off as a right click option.

              Cheers, Vikram.


              The hands that help are holier than the lips that pray.

              D Offline
              D Offline
              Dr Walt Fair PE
              wrote on last edited by
              #7

              Vikram A Punathambekar wrote:

              I remember reading a while back that a double click action should always be an 'add on' to a single click. Eg: In Explorer, single click selects a folder/file; double click selects it and then opens it.

              Actually the program pretty much does that. The single click selects the item on the list and changes it's color on the adjacent map, show that it is selected. The double click effectively displays details of the selected item. That's exactly what the MS documentations say should be done. Actually I don't mind if the Click event fires. The problem is having to more than double click to get the DoubleClick event to fire.

              The PetroNerd

              Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

              1 Reply Last reply
              0
              • A Atif Ali Bhatti

                OK. Following links can help u out. This one is Excellent and easy, http://msdn.microsoft.com/en-us/library/ms171543(VS.80).aspx[^] this one is also good. http://www.megasolutions.net/cSharp/Click-vs-DoubleClick-44615.aspx[^] Hope this solves your problem. Regards. Atif Ali Bhatti.

                D Offline
                D Offline
                Dr Walt Fair PE
                wrote on last edited by
                #8

                Thanks! I'll take a look. This works fine in other systems, so there has to be a solution.

                The PetroNerd

                Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

                D 1 Reply Last reply
                0
                • D Dr Walt Fair PE

                  Thanks! I'll take a look. This works fine in other systems, so there has to be a solution.

                  The PetroNerd

                  Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

                  D Offline
                  D Offline
                  Dr Walt Fair PE
                  wrote on last edited by
                  #9

                  Well, I looked at the links you provided and realized I had already checked them before posting my original question here. However, I also have done some more troubleshooting - and still have no idea what I'm doing wrong. I now removed the MouseClick event totally and replaced it's behavior with the SelectionChanged event. I still don't get the MouseDoubleClick event firing until the 3rd mouse click. I even removed the SelectionChanged event - same thing - it takes 3 clicks to get the MouseDoubleClick event. I guess I still have some more playing around to do. My random thought is that maybe the MouseMove event or something else is interfering, but I wouldn't have expected that at all. Is it possible that the list control doesn't have focus and it takes an extra click to get focus, then start with the double click? As you can probably tell, I'm grasping now. Thanks for the links and at least it got me thinking along a different line.

                  The PetroNerd

                  Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

                  A 1 Reply Last reply
                  0
                  • D Dr Walt Fair PE

                    Well, I looked at the links you provided and realized I had already checked them before posting my original question here. However, I also have done some more troubleshooting - and still have no idea what I'm doing wrong. I now removed the MouseClick event totally and replaced it's behavior with the SelectionChanged event. I still don't get the MouseDoubleClick event firing until the 3rd mouse click. I even removed the SelectionChanged event - same thing - it takes 3 clicks to get the MouseDoubleClick event. I guess I still have some more playing around to do. My random thought is that maybe the MouseMove event or something else is interfering, but I wouldn't have expected that at all. Is it possible that the list control doesn't have focus and it takes an extra click to get focus, then start with the double click? As you can probably tell, I'm grasping now. Thanks for the links and at least it got me thinking along a different line.

                    The PetroNerd

                    Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

                    A Offline
                    A Offline
                    Atif Ali Bhatti
                    wrote on last edited by
                    #10

                    Assalam-0-Alaikum, Well why the MouseDoubleClick event is taking 3 clicks to fire is due to the fact that you have to rollback the activity performed during the first click.. this is very important point to keep in mind. after rolling back the first click event activities, you are supposed to handle the double click event. Hope you get my point. Regards. Atif Ali Bhatti.

                    D 1 Reply Last reply
                    0
                    • A Atif Ali Bhatti

                      Assalam-0-Alaikum, Well why the MouseDoubleClick event is taking 3 clicks to fire is due to the fact that you have to rollback the activity performed during the first click.. this is very important point to keep in mind. after rolling back the first click event activities, you are supposed to handle the double click event. Hope you get my point. Regards. Atif Ali Bhatti.

                      D Offline
                      D Offline
                      Dr Walt Fair PE
                      wrote on last edited by
                      #11

                      Maybe I'm just dense, but I don't get the point. As I mentioned in another post in this thread, I've disabled the MouseClick event. It doesn't have a delegate, it doesn't do anything, the event handler has been deleted. There doesn't seem to be anything to roll back. The only mouse event I have active with a handler is MouseDoubleClick. And it still takes 3 mouse clicks to get it to fire. Obviously I'm missing something or .....

                      The PetroNerd

                      Walt Fair, Jr. Comport Computing Specializing in Technical Engineering Software

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups