Hi All,
I have a datagrid that works. When the user presses the delete button on their keyboard it seems to delete the row from the grid. How do I know what has been deleted from the grid so that I can actually remove it from my actual data. Is there an event I catch or can I compare the data in the grid with my data source.
Please help,
Danny
PS. I am using VB.NET 2003 (C# answers are fine)

How do you catch the delete event on a datagrid
Whitehorseq
http://www.windowsforms.net/Default.aspx tabindex=5&tabid=60
From the FAQ -
"When the user selects a row in the DataGridView and hits the delete key, the UserDeletingRow event fires."
Sylvain Trépanier
Their is an event that is called when you hit the delete key to delete a selected row called UserDeletingRow.
And then to get the row that being deleted
Cesar Ronchese
del.piero
I need to add a true value into e.Cancel as below,
e.Cancel = True
Beside this, can you please teach me how to write the number (no.) in datagrid first column.
I do not want to use database record's id. because it's not index from 1 to 10. Sometimes i would be 3,6,1,5,2,etc.
In this kind of situation, what i think is to write a number in front of each row. Start from 1 until the last record. Do you know how to do that Or you may have any other better solution for it.
Thanks...
Pollocks
Check out the SyncFusion DataGrid faq: http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q889q< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
-mark
Program Manager
Microsoft
This post is provided "as-is"
Vyacheslav Sidin
rurounip
Private Sub grdFunctions_UserDeletingRow work very nice...
I have coded my function as below. But in the message box. No matter i click on Yes or No. It insist to delete the selected row.
Can you please teach me what is the essential code that i missing. I only want the record to be delete when user pressing Yes. And don't do anything if user press No..
You can help me... please...
Thank
fabsecad
FcoLomas
klika84
Try this Works for DataGridViews, not sure about DataGrids.
Dim answer As Integer = MsgBox("Are you sure that, you want to delete this record ", MsgBoxStyle.YesNo, "PO System")
If answer = vbYes Then
MsgBox("Deleted.")
ElseIf answer = vbNo Then
e.Cancel
End If
Icarrus
gnich
I'm not sure I understand what you are looking to do as far as numbering the rows. If you want Row1 to have a value 1, Row2 to have a value 2, etc. then you could try something like:
Form1.DataGridView1.Rows(rowIndex).Cells(0).Value = rowIndex + 1
(+1 since the row indices are zero-based)
If that's not what you mean, then please explain your expectations a bit more clearly.