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