2 Replies - 12153 Views - Last Post: 01 February 2008 - 06:24 PM Rate Topic: -----

#1 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Cancel data delete

Post icon  Posted 31 January 2008 - 12:49 PM

Hi all

what I am trying to do is when the delete button is pressed on my binding navigator strip it gives the user the option to cancel the deletion of the entered client data from my database by using the code below.


Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

		Dim answer As Object
		answer = MessageBox.Show("Are you sure you want to delete the client data", "Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
		If answer = MsgBoxResult.Cancel = True Then

			Return
		End If

	End Sub




When the delete button is pressed the mesagebox shows. Then if the cancel button is pressed on the messagebox it still deletes the current record which is not what its supposed to do.

I have checked the output to the answer variable and it does indeed contain CANCEL so im not sure why its not working.

Using VB express 2008 with SQL express

Anybody got any suggestions :)

Is This A Good Question/Topic? 0
  • +

Replies To: Cancel data delete

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Cancel data delete

Posted 31 January 2008 - 02:33 PM

A MessageBox returns a DialogResult and you are trying to compare that to a VB6 style of MsgBox. It would be better if you did not mix VB6 with the .NET language, the only reason it is even there is for backward compatibility and will pretty soon not even exist for that reason.

It should be like this:
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

		Dim answer As DialogResult
		answer = MessageBox.Show("Are you sure you want to delete the client data", "Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
		If answer = Windows.Forms.DialogResult.Cancel Then

			Return
		End If

	End Sub

Was This Post Helpful? 0
  • +
  • -

#6 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Cancel data delete

Posted 01 February 2008 - 06:24 PM

Solved the problem with this code

Firstly set the DeleteItem property of the BindingNavigator to (none). This
stops the automatic deletion of a record. Do this in the designer, select the binding navigator then scroll thru the properties list to find the delete item.

Add this code you may have to change the private sub name


Private Sub ClientdataBindingNavigator_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ClientdataBindingNavigator.ItemClicked
		If e.ClickedItem Is Me.BindingNavigatorDeleteItem Then
			'The user clicked the delete button.
			If MessageBox.Show("Are you sure you want to delete the current record?", _
			"Confirm Delete", _
			MessageBoxButtons.OKCancel, _
			MessageBoxIcon.Question, _
			MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
				'Delete the record.
				Me.ClientdataBindingNavigator.BindingSource.RemoveCurrent()
			End If
		End If

	End Sub



You can now stop the deletion of a record if you so wish :D
Was This Post Helpful? 1

Page 1 of 1