By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Datagrid - How to Undo a delete

P: n/a
I want to asked the user if he is sure before deleting a row in a datagrid.

I've created an event handler for the underlying table using the RowDeleting
Event.

If the user responds that he does not want to delete the row then I think I
am supposed to throw an exception.

But the rowstate is changed to deleted anyway. I thought throwing the
exception would prevent this.

What am I doing wrong?

Dan


Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"DanB" <ag*****@kc.rr.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
I want to asked the user if he is sure before deleting a row in a datagrid.
I've created an event handler for the underlying table using the RowDeleting Event.

If the user responds that he does not want to delete the row then I think I am supposed to throw an exception.

But the rowstate is changed to deleted anyway. I thought throwing the
exception would prevent this.

What am I doing wrong?

Dan


You might be able to call RejectChanges on the row in question, but I have
to admit, I have not tried this approach...

Best Regards,

Andy
Nov 21 '05 #2

P: n/a
I think that will ultimately be the answer. But I Tried
Try

If MsgBox(strPrompt, MsgBoxStyle.YesNo, "Deletion Requested") =
MsgBoxResult.No Then

Throw New Exception("Row was not deleted")

End If

Exit Sub

Catch ex As Exception

MsgBox("Data not deleted")

e.Row.RejectChanges()

End Try
Where e = DataRowChangeEventArgs

And this is either ignored or the actual deletion occurs after the Catch
phrase is executed.
"Andy Becker" <x@x.com> wrote in message
news:uY**************@TK2MSFTNGP09.phx.gbl...
"DanB" <ag*****@kc.rr.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
I want to asked the user if he is sure before deleting a row in a datagrid.

I've created an event handler for the underlying table using the

RowDeleting
Event.

If the user responds that he does not want to delete the row then I

think I
am supposed to throw an exception.

But the rowstate is changed to deleted anyway. I thought throwing the
exception would prevent this.

What am I doing wrong?

Dan


You might be able to call RejectChanges on the row in question, but I have
to admit, I have not tried this approach...

Best Regards,

Andy

Nov 21 '05 #3

P: n/a
"DanB" <ag*****@kc.rr.com> wrote in message
news:uw**************@TK2MSFTNGP09.phx.gbl...
And this is either ignored or the actual deletion occurs after the Catch
phrase is executed.


I'm not sure why it wouldn't work then. Maybe there is a deep copy of the
row made internally, and the reject basically does nothing?

At this point all I can suggest is to try and get the UI confirmation
somewhere earlier in the "food chain".

Best Regards,

Andy
Nov 21 '05 #4

P: n/a
Hi,

Here is some sample code on how to create an inherited datagrid
which has a row deleted event.

http://www.onteorasoftware.com/downloads/delete.zip

Ken
---------------------
"DanB" <ag*****@kc.rr.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
I want to asked the user if he is sure before deleting a row in a datagrid.

I've created an event handler for the underlying table using the RowDeleting
Event.

If the user responds that he does not want to delete the row then I think I
am supposed to throw an exception.

But the rowstate is changed to deleted anyway. I thought throwing the
exception would prevent this.

What am I doing wrong?

Dan

Nov 21 '05 #5

P: n/a
Thanks Ken,

I thought it might be an easier process than this but so be it.

Dan

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

Here is some sample code on how to create an inherited datagrid which has a row deleted event.

http://www.onteorasoftware.com/downloads/delete.zip

Ken
---------------------
"DanB" <ag*****@kc.rr.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
I want to asked the user if he is sure before deleting a row in a datagrid.
I've created an event handler for the underlying table using the RowDeleting Event.

If the user responds that he does not want to delete the row then I think I am supposed to throw an exception.

But the rowstate is changed to deleted anyway. I thought throwing the
exception would prevent this.

What am I doing wrong?

Dan


Nov 21 '05 #6

P: n/a
I am not sure this is the best answer, but it worked for me.
I had the problem with Whidbey's new dataset methodology. I am creating
an input form.
Deleting a specific record is not allowed if the record is referenced.
I could not stop the update, but I did reverse it as follows:
------------------------
Private mAllowDelete As Boolean = False
Private Sub BeforePersonDeletion(ByVal sender As Object, ByVal e As
System.Data.DataRowChangeEventArgs)
'Reverse the deletion of a row.
Dim curRow As PersonRow = CType(e.Row, PersonRow)
Stop
mAllowDelete = DLookup("DocAuthor", "Doc", "DocAuthor=" +
curRow.ID.ToString, mCn) Is Nothing
If Not mAllowDelete Then
MsgBox("You cannot delete this person, he is the author of a
document in the database")
End If
End Sub
Private Sub AfterPersonDeletion(ByVal sender As Object, ByVal e As
System.Data.DataRowChangeEventArgs)
'Undo if we should not have deleted
If Not mAllowDelete Then
e.Row.RejectChanges()
End If
End Sub

------------------------
This is about as inelegant as it gets. I would appreciate a better
solution. It does, however work.
Leon
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

P: n/a
This almost works :D

When I do the first Delete, and click NO , it doesnt delete, but then, if I
click on another row, it deletes that row - with no notification.

wild eh.

I agree Dan, I thought it would be easier than this. I have been struggling
with a confirmation on the delete for a while now, the MS site says
just use a simple dataTable.RejectChanges on a RowDeleting event - that
didn't work, the DataGrid still reflected the delete.

Then - elsewhere - they say 'throw an exception' - ok, tried that - it
still didnt keep the DG from removing the row. (yes, I have tried a number of
other techniques)

This one looks most promising

"Dan Bacon" wrote:
Thanks Ken,

I thought it might be an easier process than this but so be it.

Dan

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

Here is some sample code on how to create an inherited

datagrid
which has a row deleted event.

http://www.onteorasoftware.com/downloads/delete.zip

Ken
---------------------
"DanB" <ag*****@kc.rr.com> wrote in message
news:eX**************@tk2msftngp13.phx.gbl...
I want to asked the user if he is sure before deleting a row in a

datagrid.

I've created an event handler for the underlying table using the

RowDeleting
Event.

If the user responds that he does not want to delete the row then I think

I
am supposed to throw an exception.

But the rowstate is changed to deleted anyway. I thought throwing the
exception would prevent this.

What am I doing wrong?

Dan



Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.