Results 1 to 5 of 5

Thread: [RESOLVED] BindingNavigatorDeleteItem VB2005 question

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Resolved [RESOLVED] BindingNavigatorDeleteItem VB2005 question

    hey everyone,

    does anyone know of a way to halt the delete functionality when a button, whether set by default when as BindingNavigator is added, or if you set a button to be the BindingNavigatorDeleteItem, is clicked? I can't seem to find anything that captures the deletion only addition of an item. i would like to be able to give the client the option to be sure they really want to delete the item.

    thanx in advance


    nevermind i figured it out just wasn't thinking about it clearly
    Last edited by vbdotnetboy; Jan 27th, 2006 at 01:56 PM. Reason: Resolved

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] BindingNavigatorDeleteItem VB2005 question

    Would you mind posting your solution to this as others have asked the same question. It's always a good idea to post your solution rather than just say you figured it out for that very reason. I've come up with the following solution but I'd be interested to know if you found something better, as I can't see anything native to the BindingNavigator itself.
    VB Code:
    1. Private deleteButton As ToolStripItem
    2.  
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.     Me.deleteButton = Me.BindingNavigator1.DeleteItem
    5. End Sub
    6.  
    7. Private Sub BindingNavigator1_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles BindingNavigator1.ItemClicked
    8.     If e.ClickedItem Is Me.deleteButton Then
    9.         'The user clicked the delete button.
    10.         If MessageBox.Show("Are you sure you want to delete the current record?", _
    11.                            "Confirm Delete", _
    12.                            MessageBoxButtons.OKCancel, _
    13.                            MessageBoxIcon.Question, _
    14.                            MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
    15.             'Allow the record to be deleted.
    16.             Me.BindingNavigator1.DeleteItem = Me.deleteButton
    17.         Else
    18.             'Don't allow the record to be deleted.
    19.             Me.BindingNavigator1.DeleteItem = Nothing
    20.         End If
    21.     End If
    22. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] BindingNavigatorDeleteItem VB2005 question

    Alright, found a better solution in this thread, which may well be what you did also.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Re: [RESOLVED] BindingNavigatorDeleteItem VB2005 question

    Well after searching a bit I found an answer to this...

    What I did
    1) copy the default delete button
    2) pasted a new one on the toolstrip 3)
    3) renamed it MyDeleteButton
    4) I deleted the default button
    5)Added this code:
    Code:
    Private Sub MyDeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyDeleteButton.Click
            Me.MyBindingSource.RemoveCurrent()
        End Sub
    Now I have a delete button I can actually add code to.


    People...for the future, if you are stumped on something and post a question then find an answer PLEASE POST IT instead of saying NM found it. Chances are if you are having a problem with something some one else has or will have the same problem.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] BindingNavigatorDeleteItem VB2005 question

    Actually, there's no need for copying or deleting any buttons. You simply set the DeleteItem property of the BindingNavigator to Nothing so it doesn't do anything automatically when the button is clicked. Then you add a Click event handler for the existing button.

    That last solution had the same effect as this because deleting the existing button would make the DeleteItem property Nothing too. It just was more work than is necessary.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width