Results 1 to 3 of 3

Thread: Key Down Event on a DataGrid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    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
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  2. #2
    Member
    Join Date
    Jun 2004
    Location
    San Diego
    Posts
    39

    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.
    Mike

  3. #3
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width