473,490 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How trap for Control Delete

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
9 1399
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
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
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
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
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
Surely there's got to be an easier way of trapping for the the use of the
Control-Delete key.
Nov 20 '05 #7
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2730
by: aj | last post by:
DB2 WSE LUW 8.1 Fixpak 5 Red Hat AS 2.1 Has anyone ever seen a db2diag.log indicate that a trap file was written, but it is *not* written? For the 3rd time in 18 months, I had a production...
3
4052
by: Detlev Ahlgrimm | last post by:
Hi! I have to use MS-Access2000 as a frontend for an oracle database. And I dont want to see these ORA-xxxx Popups if an error occures. So I use something like the following in access (it should...
2
1865
by: deko | last post by:
I use db.execute to run a delete query. I've also tried DoCmd.OpenQuery. Both work fine, but neither appears to allow me to trap an error if referential integrity is violated - in which case no...
2
8434
by: Bob Darlington | last post by:
When a user clears a value from a combo box (by pressing the delete key), the following message appears: "You tried to assign the null value to a variable that is not a variant data type". ...
10
2321
by: pemo | last post by:
As far as I understand it, a trap representation means something like - an uninitialised automatic variable might /implicitly/ hold a bit-pattern that, if read, *might* cause a 'trap' (I'm not...
3
4975
by: Robert W. | last post by:
In my WinForms app I wanted to implement a Read-Only textbox. I didn't like the appearance a textbox takes on when the ReadOnly property is set true so instead I trapped the KeyPress event with a...
2
3302
by: Charles Law | last post by:
I'll kick myself when you tell me, but ... I have a user control on a form, and I want the user control to see the arrow keys when I press them. If I press just about any other key the control's...
2
6497
by: Linda Liu[MSFT] | last post by:
Hi George, Keyboard input introduces the idea of focus. In Windows, a particular element is designated as having the focus, meaning that it acts as the target for keyboard input. The user sets...
1
1486
by: Chris Jobson | last post by:
>I have a canvas which I use for dragging shapes around such as rectangles Add Focusable="True" to the XAML for the PolyLine and Rectangle elements and then when you set the focus to them they...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.