Results 1 to 4 of 4

Thread: delete key press event?

  1. #1

    Thread Starter
    Registered User jkw119's Avatar
    Join Date
    Oct 2001
    Location
    Pittsburgh
    Posts
    256

    delete key press event?

    i want to not let the user press the delete key on a data grid. in the datagrid keypress event, i have tried everything...

    VB Code:
    1. Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
    2.         If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Delete) Then
    3.             MsgBox("delete")
    4.         End If
    5.         If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
    6.             MsgBox("enter")
    7.         End If
    8.     End Sub
    9.  
    10.  
    11.     Private Sub DataGrid1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGrid1.KeyDown
    12.         Select Case e.KeyCode
    13.             Case Keys.Delete
    14.                 MessageBox.Show("You pressed delete")
    15.         End Select
    16.     End Sub

    the enter is the only thing that works. I am wondering, is there an event with the delete key, and second, how can you not let a user delete a row from a datagrid, but keep a datagrid editable.

    thanks,

    jeff

  2. #2
    Member BinaryAnge's Avatar
    Join Date
    Jun 2002
    Location
    Columbus,Ohio
    Posts
    51

    I HAD THE SAME PROBLEM

    you need to use the key up event.
    The Programmers Credo -
    Protect dumb-ass from himself.

  3. #3
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    At the end of your event add:

    e.Handled = True

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You need to use the keyup or keydown event of the datagrid control in order to sink function and control keys.

    Code:
        Private Sub DataGrid1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGrid1.KeyDown
            If e.KeyCode = Keys.Delete Then
                e.Handled = True
            End If
        End Sub

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