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
  1. Home
  2. General Programming
  3. C#
  4. Winform DataGridView

Winform DataGridView

Scheduled Pinned Locked Moved C#
tutorialquestion
7 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.
  • J Offline
    J Offline
    jason_mf
    wrote on last edited by
    #1

    DataGridView's SelectionChanged Event Fire earlier than CellDoubleClick Event. But I hope SelectionChanged after CellDoubleClick. My Program require: 1> DoubleClick any part of the row, this row selected=true. read a value from this row as parameter order to open a dialog for do something. 2> When SelectionChanged, another controls's value will changed from the new selected row. But if DoubleClick fired that another controls's value need not change. How to do? Thanks.

    L G 2 Replies Last reply
    0
    • J jason_mf

      DataGridView's SelectionChanged Event Fire earlier than CellDoubleClick Event. But I hope SelectionChanged after CellDoubleClick. My Program require: 1> DoubleClick any part of the row, this row selected=true. read a value from this row as parameter order to open a dialog for do something. 2> When SelectionChanged, another controls's value will changed from the new selected row. But if DoubleClick fired that another controls's value need not change. How to do? Thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      WinForm Controls often fire more events than you would expect. Maybe SelectionChanged fires more than once, say first to indicate a possible previous selection is no longer selected, then to tell you something new is selected. And some other events may be present in between. Suggestion: Add some logging to your event handlers to see what happens in sufficient detail. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • J jason_mf

        DataGridView's SelectionChanged Event Fire earlier than CellDoubleClick Event. But I hope SelectionChanged after CellDoubleClick. My Program require: 1> DoubleClick any part of the row, this row selected=true. read a value from this row as parameter order to open a dialog for do something. 2> When SelectionChanged, another controls's value will changed from the new selected row. But if DoubleClick fired that another controls's value need not change. How to do? Thanks.

        G Offline
        G Offline
        GenJerDan
        wrote on last edited by
        #3

        Maybe not use DoubleClick and SelectionChanged? Use MouseDown, instead, and test for how many clicks?

                if (e.Button == MouseButtons.Left)
                {
                    if (e.Clicks == 1)
                      {
                        DoSelectionstuff();
                      }
                else if (e.Clicks == 2)              
                  {
                    DoDoubleclickStuff();
                  }
        

        Might not work... But you can set a flag in the MouseDown event indicating whether it was a 1 or a 2 click, then process your SelectionChange code appropriately.

        There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.

        J 1 Reply Last reply
        0
        • G GenJerDan

          Maybe not use DoubleClick and SelectionChanged? Use MouseDown, instead, and test for how many clicks?

                  if (e.Button == MouseButtons.Left)
                  {
                      if (e.Clicks == 1)
                        {
                          DoSelectionstuff();
                        }
                  else if (e.Clicks == 2)              
                    {
                      DoDoubleclickStuff();
                    }
          

          Might not work... But you can set a flag in the MouseDown event indicating whether it was a 1 or a 2 click, then process your SelectionChange code appropriately.

          There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.

          J Offline
          J Offline
          jason_mf
          wrote on last edited by
          #4

          e.clicks is always 1

          G 1 Reply Last reply
          0
          • J jason_mf

            e.clicks is always 1

            G Offline
            G Offline
            GenJerDan
            wrote on last edited by
            #5

            Really? Not in my app. I had to use it to prevent row selection on doubleclicks. Hmm.

            There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.

            J 1 Reply Last reply
            0
            • G GenJerDan

              Really? Not in my app. I had to use it to prevent row selection on doubleclicks. Hmm.

              There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.

              J Offline
              J Offline
              jason_mf
              wrote on last edited by
              #6

              I try to again. not always 1, but first click still call DoSelectionSuff() Then call DoDoubleClickSuff()

              G 1 Reply Last reply
              0
              • J jason_mf

                I try to again. not always 1, but first click still call DoSelectionSuff() Then call DoDoubleClickSuff()

                G Offline
                G Offline
                GenJerDan
                wrote on last edited by
                #7

                Ah... Try moving the code currently in the OndoubleClick into a separate function (use the Refactor tool to create the function), then "disconnect" the event from the grid. Call the separate function from the MouseDown event when 2 clicks are seen. If it doesn't work, just reconnect the DoubleClick. No harm done. :)

                There is water at the bottom of the ocean. My Mu[sic] My Films My Windows Programs, etc.

                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