Results 1 to 3 of 3

Thread: Delete key keypress

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    83

    Delete key keypress

    Hi,


    I've noticed that when I press the delete key my current row is deleted in my datagrid.

    What is the event for this and how can I carry another operation under this event when the delete key is pressed.

    I could do the operation under this event right
    Code:
    private void DataGridView_KeyPress(object sender, KeyPressEventArgs e)
            {
    How do I check whether the Delete key was pressed
    Last edited by sunshine123; Apr 14th, 2007 at 07:56 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Delete key keypress

    There are three events that relate to keystrokes: KeyDown, KeyPress and KeyUp. KeyDown and KeyUp relate to individual keys on the keyboard and are raised for all keys. KeyPress relates to characters that are sent to the control. For instance, if you press Shift+C you will get two KeyDown and two KeyUp events because you pressed two keys, but only one KeyPress event because only one character is sent to the control. The Delete key does not send a character to the control so it doesn't raise a KeyPress event. You can handle the KeyDown event and test the e.KeyCode property.

    Having said that, if your DataGrid is bound to a DataTable I'd be more inclined to handle its RowDeleting or RowDeleted event.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    83

    Re: Delete key keypress

    Ok thanks I willl check that out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width