Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable the "CTRL-X" in a datagrid? 3

Status
Not open for further replies.

todd666

IS-IT--Management
Dec 3, 2001
61
CA
Is it possible to prevent the use of "CTRL-X" in the cell of the datagrid?
 
'bout the only thing I can think of is to make the datagrid read only (DataGrid.AllowUpdate = FALSE). An attempt to cut the contents of a cell (CTRL-X) will then fail because it's an attempt to modify data in the grid.
 
You can also use a keyboard hook and subclass it. Do a search in this forum for keyboard hook and you'll find something to help you out.
 
Start with this idea
Ctrl+A = 1, Ctrl+Z=26

Private Sub DataGrid1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles DataGrid1.KeyPress
Dim byt As Byte = Convert.ToByte(e.KeyChar)
#If Debug then
MessageBox.Show("Byte=" & byt.ToString("##"))
#End If
If byt = 24 Then ' Ctrl+X
e.Handled = True
End If
End Sub

Compare Code
 
Nice one John, but it looks a bit like VB.NET!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Try,

Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift And vbCtrlMask Then
If KeyCode = vbKeyX Then
Debug.Print "You pressed ctrl + x"
'Discard the key
KeyCode = 0
End If
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top