|
-
Oct 4th, 2002, 03:42 PM
#1
Thread Starter
Registered User
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:
Private Sub DataGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DataGrid1.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Delete) Then
MsgBox("delete")
End If
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
MsgBox("enter")
End If
End Sub
Private Sub DataGrid1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGrid1.KeyDown
Select Case e.KeyCode
Case Keys.Delete
MessageBox.Show("You pressed delete")
End Select
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
-
Oct 4th, 2002, 04:09 PM
#2
Member
I HAD THE SAME PROBLEM
you need to use the key up event.
The Programmers Credo -
Protect dumb-ass from himself.
-
Oct 4th, 2002, 07:40 PM
#3
Fanatic Member
At the end of your event add:
e.Handled = True
-
Oct 4th, 2002, 09:46 PM
#4
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|