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!

delete a row in a DataGrid

Status
Not open for further replies.

Tailgun

Technical User
Joined
Mar 30, 2002
Messages
417
Location
US
I know I can select a row in a DataGrid and use the Delete key to remove that row, but how can I select a row in a DataGrid and use a cmd Button to Delete that row ??


Thanks for any and all help
 
Maybe I could just use this ??? in the cmd button click event

cmdDelete_KeyPress(KeyAscii As Integer)
KeyAscii = ??????


but I would need to know the Key Ascii for the Delete key.

Anyone think this might work???
 
the key code is 46 but I can't seem to get that to work either

 
Anyone know the answer??

Also the cmd button (Delete) is disabled and I would like to enable it when the user selects a row in the DataGrid. There must be a way other than the user using the Delete key to delete a row in a DataGrid by using a cmd button.

Thanks for any and all help
 
Have you tried using: SendKeys "{Delete}"


One way would be to add a menu with the Menu Editor. Then you can add a DataGridMenu which could include Copy, Cut, Delete, Paste, etc...

After this is done, the user can right click with the Mouse Down function on the data grid, and then click the Delete menu item.

Then you use the sendkeys command to send the "Delete" key.

Example:

Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
If Me.DataGrid1.Columns(0).CellText(Me.DataGrid1.Bookmark) = "" Then
Me.mnuPunchCopy.Enabled = False
Me.mnuPunchCut.Enabled = False
Else
Me.mnuPunchCopy.Enabled = True
Me.mnuPunchCut.Enabled = True
End If
PopupMenu mnuPunchList
End If
End Sub


Private Sub mnuPunchCut_Click()
Call mnuPunchCopy_Click 'copy into array for paste later
SendKeys "{Delete}" 'delete key
End Sub

 
Thanks alot for your help PSAARON,

My problem is the client wants to maintain the look of this back when it was an excel app.

So I'm trying my best to maintain the look and feel of what has been previously done. If I can't find some way to use a cmdButton that is enabled when a row in the datagrid is selected and then have the cmdbutton delete that row I guess I will have to try and convince him your approach is alot better. BTW I agree your approach would be much better.

Thanks again for helping
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top