Cancel a delete operation

  • Thread starter Thread starter Roshawn
  • Start date Start date
R

Roshawn

Hi,

I am trying to cancel the deletion of a datarow. When the user presses the
Delete button, a messagebox displays asking the user if they really want to
delete the current row. If "Yes", then the delete occurs; if "No", then the
current row remains in the table and is not marked for deletion.

My problem is that if the user presses the "No" button on the messagebox the
row is still removed from the table (marked for deletion). How can I stop
that from happening using the above code description?

Here's my code:
******************************
With Me.BindingContext(dvCustomers) ' references a dataview object
Select Case CType(sender, Button).Name
'other case statements are omitted here; they work fine
Case "btnDelete"
MsgBox("Are you sure you want to delete the current row?", &
_
MsgBoxStyle.YesNo, "Delete Row")
If MsgBoxResult.Yes Then
.RemoveAt(.Position)
UpdatePosition() 'utility method
End If
If MsgBoxResult.No Then
.Position = .Position 'problem occurs here - need
help
End If
End Select

******************************

Thanks,
Roshawn
 
Hi Roshawn,

You have to use the value MsgBox returns you:
MsgBoxResult result = MsgBox("Are you sure you want to delete the current row?", &
_
MsgBoxStyle.YesNo, "Delete Row")
If result = MsgBoxResult.Yes Then
.RemoveAt(.Position)
UpdatePosition() 'utility method
End If
If result = MsgBoxResult.No Then ' or just use Else
.Position = .Position 'problem occurs here - need
help
End If
 
Hi Miha,

Thank you for your promp response. Man, am I grateful to these newsgroups!!
Your solution worked perfectly!

Roshawn
 
Back
Top