Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,914 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,167 people online right now. Registration is fast and FREE... Join Now!




Cancel data delete

 
Reply to this topicStart new topic

Cancel data delete

sharpy
31 Jan, 2008 - 11:49 AM
Post #1

D.I.C Head
Group Icon

Joined: 2 Jun, 2007
Posts: 206



Thanked: 2 times
Dream Kudos: 275
My Contributions
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.

CODE


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 smile.gif


User is offlineProfile CardPM
+Quote Post

Jayman
RE: Cancel Data Delete
31 Jan, 2008 - 01:33 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,317



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
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:
CODE

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




User is online!Profile CardPM
+Quote Post

sharpy
RE: Cancel Data Delete
1 Feb, 2008 - 05:24 PM
Post #3

D.I.C Head
Group Icon

Joined: 2 Jun, 2007
Posts: 206



Thanked: 2 times
Dream Kudos: 275
My Contributions
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

CODE


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 biggrin.gif


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 02:11PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month