Keypress capture when multicell selected within DataGridView

kriswinner

Member
Joined
Apr 23, 2009
Messages
23
Programming Experience
10+
I'm sure this is simple, but I can't seem to find a reference for this specific situation.

I'm using a datagridview that I'd like to have the user be able to select multiple cells within a row and then allow them to press <Delete> to delete the values within the cells.

I can't seem to capture the KeyPress event.

Thanks in advance for your help.
 
VB.NET:
Private Sub DataGridView1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyUp
    If e.KeyCode = Keys.Delete Then
        For Each cell As DataGridViewCell In Me.DataGridView1.SelectedCells
            cell.Value = Nothing
        Next
    End If
End Sub
 
Thanks for the help, JohnH.

Not sure why it was having issues before, but your code worked fine.
I did change the .KeyUp to .KeyDown to make it operate the same way that Excel does.

Again, thanks!
 

Latest posts

Back
Top