Key Down Event on a DataGrid
I am trying to add a KeyDown event for a datagrid, specifically to catch the Delete key to Delete the row of data. The DataGrid is set to ReadOnly, but it seems like half the time I press Delete the row tries to go into edit mode and the event never fires. Anybody have any idea what would cause this? Here's the event code:
Private Sub dgMaintenance_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgMaintenance.KeyDown
Dim mbrResult As MsgBoxResult ' Confirmation result
Dim boolResult As Boolean ' Delete result
' If a row is selected
If e.KeyCode = Keys.Delete And dgMaintenance.CurrentRowIndex > -1 Then
' Confirm they want to do this
mbrResult = MsgBox("Are you sure you wish to delete this Scheduled Maintenance?", _
MsgBoxStyle.YesNo, "Warning! Scheduled Maintenance Deletion")
' If Deletion is confirmed
If mbrResult = MsgBoxResult.Yes Then
' Attempt to Delete this Scheduled maintenance
boolResult = oNRS_SQL.DeleteMaintenanceRecord(dgMaintenance.Item(dgMaintenance.CurrentRowIndex, 0))
' If Deletion is not successful
If boolResult = False Then
' Pop an error message
MsgBox("Unable to delete Scheduled Maintenance", MsgBoxStyle.Critical, "Database Error")
Else
' Reload the Maintenance schedule
oNRS_SQL.LoadMaintenanceSchedule(m_intResourceID)
End If
End If
End If
End Sub
Re: Key Down Event on a DataGrid
Hi,
I have the same problem!! Did you get any help on this issue? I'm trying to get a confirmation from the user before deleting a row. Any idea? Thanks.
Re: Key Down Event on a DataGrid
what about this, i have asked these questions before and my fellows here have helped me.
check this thread, i was the one who started it so you might rate me for directing it again to you . it took me a couple of minutes to find it in the site, you should search the forums before making new threads
anyway here is the link
the same thread asked by Me
hope you like it
rgds