DataGrid and rejecting changes

  • 11 years ago

    Using a messagebox to give the user a choice(Yes/No). When I choose - No - it still removes the info from the datagrid and lowers the number on the navigator by 1. How can I alter this code to not remove the data in the datagrid and not change the count in the navigator when No is selected?

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

    myConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HomeInventory.mdf;Integrated Security=True; Connect Timeout=30;User Instance=True;")

    Dim myAdapter As SqlDataAdapter = New SqlDataAdapter("DeleteItem", myConnection)

    If MessageBox.Show("Are you sure you want to delete this record? ", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then

    Exit Sub

    ElseIf (Windows.Forms.DialogResult.Yes) Then

    Dim ds As DataSet = New DataSet

    myAdapter.SelectCommand.CommandType = CommandType.StoredProcedure


    New SqlParameter("@ItemID", SqlDbType.Int))


    "@ItemID").Value = ItemIDTextBox.Text




    End If




  • 11 years ago


    Made 2 changes:

    1. Set the BindingNavigators DeleteItems to None and

    2 added BindingSource.RemoveCurrent()


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond