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. Delete Key Trapping?

Delete Key Trapping?

Scheduled Pinned Locked Moved C#
cssquestion
3 Posts 2 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
    jasper018
    wrote on last edited by
    #1

    Hello I have a data grid view and when I press the delete key, even though I have a message box to confirm the delete, the delete happens either way. Any ideas on trapping the delete key? thanks j private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { DialogResult yn = MessageBox.Show("Are you sure you want to delete this row?", "DataGridView Delete", MessageBoxButtons.YesNo); if (yn == DialogResult.Yes) { } if (yn == DialogResult.No) { MessageBox.Show("record was not deleted"); } }

    A 1 Reply Last reply
    0
    • J jasper018

      Hello I have a data grid view and when I press the delete key, even though I have a message box to confirm the delete, the delete happens either way. Any ideas on trapping the delete key? thanks j private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { DialogResult yn = MessageBox.Show("Are you sure you want to delete this row?", "DataGridView Delete", MessageBoxButtons.YesNo); if (yn == DialogResult.Yes) { } if (yn == DialogResult.No) { MessageBox.Show("record was not deleted"); } }

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      Just use the KeyDown event for your datatgrid. The keydown event gets fired before the control knows about a key being pressed. Then you can check if the key pressed was the delete key, and then if you want to cancel the delete, set e.Handled to true.

      My current favourite word is: PIE! Good ol' pie, it's been a while.

      J 1 Reply Last reply
      0
      • A Anthony Mushrow

        Just use the KeyDown event for your datatgrid. The keydown event gets fired before the control knows about a key being pressed. Then you can check if the key pressed was the delete key, and then if you want to cancel the delete, set e.Handled to true.

        My current favourite word is: PIE! Good ol' pie, it's been a while.

        J Offline
        J Offline
        jasper018
        wrote on last edited by
        #3

        Thanks I am going to give that a try! J

        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