none
How to cancel BindingNavigator Add New Item?

    Question

  • Is there a way to cancel the BindingNavigator Add New Item before a new record is created? 

    e.g. prompt the user for information before adding the new record and cancel if the information is incomplete/dialogresult is canceled.

    Thank you. -ME

    Friday, March 24, 2017 10:39 AM

Answers

  • One way to accomplish this is to use a secondary form, place controls e.g. TextBox onto this form along with two buttons, one to accept, one to cancel. Both buttons you set the DialogResult, one to OK, one to Cancel. Show the form modally e.g. ShowDialog then on form close check if the result was ok or cancel.

    Private Sub cmdAddNewRecord_Click(sender As Object, e As EventArgs) Handles cmdAddNewRecord.Click
        Dim f As New Form2
        Try
            If f.ShowDialog = DialogResult.OK Then
                ' do validation on information from the child form
                ' if validates, add new record
            Else
                ' use cancelled
            End If
        Finally
            f.Dispose()
        End Try
    End Sub

    Adding the row demo

    SomeDataSet.TableName.AddTableNameRow(....

    Here is an example for a Customer table where test in the field would be say text boxes from the child form.

    Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) _
        Handles BindingNavigatorAddNewItem.Click
    
        NorthDataSet.Customers.AddCustomersRow(
            "Test company",
            "test", "test",
            "test", "test",
            "test", "test",
            "test", "test",
            "test")
    End Sub

    In the BindingNavigator I set the Add new to none

    Customers schema


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Monday, March 27, 2017 9:40 AM
    Moderator
  • Hi kingelk,

    Firstly, you could clear the BindNavigator “AddNewItem” property in Properties windows, so that is doesn’t fire bindsource AddingNew.

    Secondly, double click on the plus sign in bingingNavigator to generate click event for the plus button and manually control add new item procedure,

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by kingelk Tuesday, March 28, 2017 10:02 AM
    Monday, March 27, 2017 8:50 AM
    Moderator

All replies

  • In the way you ask this, it is possible with the databindingevents. 


    http://www.vb-tips.com/DataBindingEvents.aspx


    Success
    Cor



    Friday, March 24, 2017 10:54 AM
  • Hi kingelk,

    Firstly, you could clear the BindNavigator “AddNewItem” property in Properties windows, so that is doesn’t fire bindsource AddingNew.

    Secondly, double click on the plus sign in bingingNavigator to generate click event for the plus button and manually control add new item procedure,

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by kingelk Tuesday, March 28, 2017 10:02 AM
    Monday, March 27, 2017 8:50 AM
    Moderator
  • One way to accomplish this is to use a secondary form, place controls e.g. TextBox onto this form along with two buttons, one to accept, one to cancel. Both buttons you set the DialogResult, one to OK, one to Cancel. Show the form modally e.g. ShowDialog then on form close check if the result was ok or cancel.

    Private Sub cmdAddNewRecord_Click(sender As Object, e As EventArgs) Handles cmdAddNewRecord.Click
        Dim f As New Form2
        Try
            If f.ShowDialog = DialogResult.OK Then
                ' do validation on information from the child form
                ' if validates, add new record
            Else
                ' use cancelled
            End If
        Finally
            f.Dispose()
        End Try
    End Sub

    Adding the row demo

    SomeDataSet.TableName.AddTableNameRow(....

    Here is an example for a Customer table where test in the field would be say text boxes from the child form.

    Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) _
        Handles BindingNavigatorAddNewItem.Click
    
        NorthDataSet.Customers.AddCustomersRow(
            "Test company",
            "test", "test",
            "test", "test",
            "test", "test",
            "test", "test",
            "test")
    End Sub

    In the BindingNavigator I set the Add new to none

    Customers schema


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Monday, March 27, 2017 9:40 AM
    Moderator