David Svedarsky
asked on
How to create a message box to cancel record delete
This is databound:
I am looking for sample code to create a message box that will cancel a BindingNavigatorDeleteItem record delete.
This does not work:
Private Sub BindingNavigatorDeleteItem _Click(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem .Click
If MessageBox.Show("Are you sure?", "Delete Row", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult .No Then
End If
Everything I have tried will not cancel the event.
I am looking for sample code to create a message box that will cancel a BindingNavigatorDeleteItem
This does not work:
Private Sub BindingNavigatorDeleteItem
If MessageBox.Show("Are you sure?", "Delete Row", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult
End If
Everything I have tried will not cancel the event.
ASKER
vbturbo,
Yes to your question.
Yes to your question.
Im not quite sure if i got the grasp of your question
maybee this is what you mean
Dim msg As String = "The data will be permanently lost.?"
If MessageBox.Show(msg, "Deleting Data File", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu tton2) = DialogResult.Yes Then
else
Exit sub
End If
maybee this is what you mean
Dim msg As String = "The data will be permanently lost.?"
If MessageBox.Show(msg, "Deleting Data File", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Bu
else
Exit sub
End If
I see ,,, sorry for my late binding of concepts -:)
Private Sub BindingNavigatorDeleteItem _Click(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem .Click
If (Me.Validate() And Not (CustomersBindingSource Is Nothing)) Then
If (MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
CustomersBindingSource.Rem oveCurrent ()
CustomersBindingSource.End Edit()
'Me.TableAdapter.Update(Me .DataSet.N ame)
End If
End If
End Sub
this should do it
vbturbo
Private Sub BindingNavigatorDeleteItem
If (Me.Validate() And Not (CustomersBindingSource Is Nothing)) Then
If (MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
CustomersBindingSource.Rem
CustomersBindingSource.End
'Me.TableAdapter.Update(Me
End If
End If
End Sub
this should do it
vbturbo
ASKER
vbturbo,
This is what I mean except on this code and all I have tried - if you click "No" - the record is deleted.
(Clicking "No" does not cancel the delete)
This is what I mean except on this code and all I have tried - if you click "No" - the record is deleted.
(Clicking "No" does not cancel the delete)
Set the DeleteButton member on the BindingNavigator to Nothing and then hook the Delete Button Click yourself.
Try this
Set the DeleteButton member on the BindingNavigator to Nothing and then hook the Delete Button Click yourself
Private Sub BindingNavigatorDeleteItem _Click(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem .Click
If (Me.Validate() And Not (CustomersBindingSource Is Nothing)) Then
If (MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
CustomersBindingSource.Rem oveCurrent ()
CustomersBindingSource.End Edit()
'Me.TableAdapter.Update(Me .DataSet.N ame)
End If
End If
End Sub
Set the DeleteButton member on the BindingNavigator to Nothing and then hook the Delete Button Click yourself
Private Sub BindingNavigatorDeleteItem
If (Me.Validate() And Not (CustomersBindingSource Is Nothing)) Then
If (MsgBox("Delete?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
CustomersBindingSource.Rem
CustomersBindingSource.End
'Me.TableAdapter.Update(Me
End If
End If
End Sub
ASKER
vbturbo,
I tried your last comment - still doesn't work - deletes the record when clicking "No" or "Cancel".
I tried your last comment - still doesn't work - deletes the record when clicking "No" or "Cancel".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you talking about a a ToolStripItem that represents the Delete button for the BindingSource. ?
http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingnavigator.deleteitem.aspx
http://msdn2.microsoft.com/en-us/library/system.windows.forms.bindingnavigator.deleteitem.aspx
ASKER
vbturbo,
Sorry, I missed the propery setting.
Works great!
Thanks,
Dave
Sorry, I missed the propery setting.
Works great!
Thanks,
Dave
just glad you got it Dave
good stuff guys! One quick question. by removing the deleteitem property and setting it to None, will this ensure that the removecurrent and endedit methods will truly delete the record from the database without any further coding? Because before it was removing the record by itself but not truly deleting the record. yes, it removes it from the dataset, but if you restart your application the record was coming back.
MessageBox.Show("text","ca
Or some kind of rollback
vbturbo