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. DataGridView DoubleClick Event handler fails when CTRL key is held while DoubleClicking

DataGridView DoubleClick Event handler fails when CTRL key is held while DoubleClicking

Scheduled Pinned Locked Moved C#
databasehelpquestion
3 Posts 1 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.
  • A Offline
    A Offline
    alanteigne
    wrote on last edited by
    #1

    Hello, I have a DataGridView that is dynamically populated and configured for row select, multiselect = no. When a row is double clicked, an event handler is fired which runs a function based on the Row index. The row index is referenced as follows: myDgv.SelectedRows[0].Cells[2].Value.ToString() This works great, until the user is holding the CTRL key while double clicking. I get an "index out of range error", making me think holding the CTRL key changes the value the above code returns. Has anyone ran into this before? I'm not sure what to do, other than catch the error and fail the event. Any ideas are appreciated! Thanks, Alan

    A 1 Reply Last reply
    0
    • A alanteigne

      Hello, I have a DataGridView that is dynamically populated and configured for row select, multiselect = no. When a row is double clicked, an event handler is fired which runs a function based on the Row index. The row index is referenced as follows: myDgv.SelectedRows[0].Cells[2].Value.ToString() This works great, until the user is holding the CTRL key while double clicking. I get an "index out of range error", making me think holding the CTRL key changes the value the above code returns. Has anyone ran into this before? I'm not sure what to do, other than catch the error and fail the event. Any ideas are appreciated! Thanks, Alan

      A Offline
      A Offline
      alanteigne
      wrote on last edited by
      #2

      I think it may have something to do with the index being cell based rather than row based if I hold CTRL. CTRL modifies selection in Windows (as in selecting multiple files at once, or multiple listbox lines at once).

      A 1 Reply Last reply
      0
      • A alanteigne

        I think it may have something to do with the index being cell based rather than row based if I hold CTRL. CTRL modifies selection in Windows (as in selecting multiple files at once, or multiple listbox lines at once).

        A Offline
        A Offline
        alanteigne
        wrote on last edited by
        #3

        Ok, figured it out. When I doubleclick on a row while holding CTRL, the dialog selects the row on the first click, but deselects it on the second. The DoubleClick eventhandler fires, references the selected row, and fails as none are selected.

        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