By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

How trap for Control Delete

P: n/a
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


Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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

-----Original Message-----
On a winform, how do I trap for the user pressing Control Delete? I thoughtperhaps something like the following in the keydown event of the grid, butthe code below does not work.

If e.KeyCode = Keys.ControlKey.Delete Then

MsgBox("You pressed Control Delete")

End If


.

Nov 20 '05 #2

P: n/a
Hi,

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

MessageBox.Show("Control Delete")

End If

Ken

-----------------

"Woody Splawn" <wo***@splawns.com> wrote in message
news:OH**************@TK2MSFTNGP12.phx.gbl...
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


Nov 20 '05 #3

P: n/a
Ken,

The code you advised me to use does not work for me when placing it in
the KeyDown event of the datagrid.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
Hi,

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

MessageBox.Show("Control Delete")

End If

Ken

Nov 20 '05 #4

P: n/a
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?

Nov 20 '05 #5

P: n/a
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

------------------------

"Woody Splawn" <wo***@splawns.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
Ken,

The code you advised me to use does not work for me when placing it in
the KeyDown event of the datagrid.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
Hi,

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

MessageBox.Show("Control Delete")

End If

Ken


Nov 20 '05 #6

P: n/a
Surely there's got to be an easier way of trapping for the the use of the
Control-Delete key.
Nov 20 '05 #7

P: n/a
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
Nov 20 '05 #8

P: n/a
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.

Nov 20 '05 #9

P: n/a
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.

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.