How trap for Control Delete

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

On a winform, how do I trap for the user pressing Control Delete? I thought
perhaps something like the following in the keydown event of the grid, but
the code below does not work.

If e.KeyCode = Keys.ControlKey.Delete Then

MsgBox("You pressed Control Delete")

End If
 
What operating system are you using? If Win 2k then forget
it

I have a low level keyboard hook class. Email me & I'll
send you it
 
Hi,

If e.KeyCode = Keys.Delete And e.Modifiers = Keys.Control Then

MessageBox.Show("Control Delete")

End If



Ken
 
Ken,

The code you advised me to use does not work for me when placing it in
the KeyDown event of the datagrid.
 
What operating system are you using? If Win 2k then forget
it

I am using WIndows XP. But what do you mean forget it? Is there some reason
why trapping for Control-Delete is particularly difficult?
 
Hi,

Add a handler to the keypress of each datagrid column.
Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim da As OleDbDataAdapter

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn += "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)

da.Fill(ds, "Categories")



SetupGrid()

dv = New DataView(ds.Tables("Categories"))

With dv

..AllowNew = False

..AllowEdit = True

..AllowDelete = False

End With

DataGrid1.DataSource = dv

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Categories"

Dim colPhoto As New DataGridTextBoxColumn

With colPhoto

..MappingName = "Picture"

..HeaderText = "Photo"

..Width = 150

End With

AddHandler colPhoto.TextBox.KeyDown, AddressOf DataGrid1_KeyDown

Dim colName As New DataGridTextBoxColumn

With colName

..MappingName = "CategoryName"

..HeaderText = "Name"

..Width = 80

End With

AddHandler colName.TextBox.KeyDown, AddressOf DataGrid1_KeyDown

Dim colDescription As New DataGridTextBoxColumn

With colDescription

..MappingName = "Description"

..HeaderText = "Description"

..Width = 80

End With

AddHandler colDescription.TextBox.KeyDown, AddressOf DataGrid1_KeyDown

ts.GridColumnStyles.Add(colPhoto)

ts.GridColumnStyles.Add(colName)

ts.GridColumnStyles.Add(colDescription)

DataGrid1.TableStyles.Add(ts)

ts = Nothing

colDescription = Nothing

colName = Nothing

colPhoto = Nothing

End Sub

Private Sub DataGrid1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles DataGrid1.KeyDown

If e.KeyCode = Keys.Delete And e.Modifiers = Keys.Control Then

MessageBox.Show("Control Delete")

End If

End Sub



Ken
 
Surely there's got to be an easier way of trapping for the the use of the
Control-Delete key.
 
For anyone intersted, I find the following seems to do the trick.

If e.Control Then
If e.KeyCode = Keys.Delete Then
MsgBox("Control Delete is selected")
End If
Exit Sub
End If
 
Hi Woody,

You may also try the code below. I have tested , it will work on Windows
2000.

Private Sub DataGrid1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles DataGrid1.KeyDown
If e.Control And e.KeyCode = Keys.Delete Then
Debug.WriteLine("Ctrl_Delete")
MsgBox("Ctrl_Delete")
End If
End Sub

Private Sub DataGrid1_ControlAdded(ByVal sender As Object, ByVal e As
System.Windows.Forms.ControlEventArgs) Handles DataGrid1.ControlAdded
AddHandler e.Control.KeyDown, AddressOf DataGrid1_KeyDown
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Woody,

Did you have any concern on this issue?
If so please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top