8 Replies - 5282 Views - Last Post: 07 October 2012 - 10:22 AM Rate Topic: -----

#1 maiOHmai  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 09-July 12

problem in delete button on BindingNavigator

Posted 25 September 2012 - 06:19 AM

good day! i need some help. Here is my case, i have a form that uses binding navigator which has delete button. my problem is that, though i don't receive error messages, the delete button does not really deletes the record from the database.
here is the code i'm using.

 Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            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
                Me.DetailsBindingNavigator2.BindingSource.RemoveFilter()
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub



on this line
 Me.DetailsBindingNavigator2.BindingSource.RemoveFilter()
, i tried to change it to
 Me.DetailsBindingNavigator2.BindingSource.RemoveCurrent()
, but still nothing happens.

Is This A Good Question/Topic? 0
  • +

Replies To: problem in delete button on BindingNavigator

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: problem in delete button on BindingNavigator

Posted 25 September 2012 - 06:26 AM

Not 100% sure as I don't use the binding navigator often, but I'm pretty sure that using the navigator, if you delete a record, you then have to click the save button.
Was This Post Helpful? 0
  • +
  • -

#3 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: problem in delete button on BindingNavigator

Posted 25 September 2012 - 06:42 AM

View PostCharlieMay, on 25 September 2012 - 09:26 AM, said:

Not 100% sure as I don't use the binding navigator often, but I'm pretty sure that using the navigator, if you delete a record, you then have to click the save button.


This.
If you look at the code for the save button I'm pretty sure you'll see it does an update.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: problem in delete button on BindingNavigator

Posted 25 September 2012 - 06:47 AM

I guess I should add that you don't HAVE to physically press the save button, but you at least need to also execute that same code after you delete to commit those changes.
Was This Post Helpful? 0
  • +
  • -

#5 maiOHmai  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 09-July 12

Re: problem in delete button on BindingNavigator

Posted 25 September 2012 - 07:13 AM

thnks, i think that's the answer. but i tried what you've suggested, to include the code of "save button" with the delete, i use this code:
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            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
                Me.DetailsBindingNavigator2.BindingSource.RemoveFilter()
            End If
            Me.Validate()
            Me.DetailsBindingSource2.EndEdit()
            Me.TableAdapterManager2.UpdateAll(Me.DataSet3)
            MsgBox("Record Successfully Removed")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


but it doesn't work. is there something wrong with my code? i also tried to separate the delete and the save and it does work. but what i really want is when i clicked the delete button, i will (at the same time) saved the changes (just like what you've suggested.)
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: problem in delete button on BindingNavigator

Posted 25 September 2012 - 07:49 AM

Shouldn't that be RemoveCurrent() instead of RemoveFilter()
Was This Post Helpful? 0
  • +
  • -

#7 maiOHmai  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 09-July 12

Re: problem in delete button on BindingNavigator

Posted 25 September 2012 - 07:58 AM

YEAH! sorry it's my fault. but thanks anyway.
Was This Post Helpful? 0
  • +
  • -

#8 maiOHmai  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 09-July 12

Re: problem in delete button on BindingNavigator

Posted 28 September 2012 - 10:33 PM

It's been days, since my last post. it just happened that this error occured,

Quote

Current item cannot be removed from the list because there is no current item.

every time i delete a record.

This is the scenario:
i searched for record having "a" in their title, it will then show results (i use binding navigator in Details).
First Problem.
if the result is more than one (1), for example it displayed three (3) records and i press the delete button, 2 records that is displayed will be removed, one(1) was removed permanently and the other was removed just from the list.

Second Problem.
if the result is only one (1), then the above error occurs.

this is the code i'm using for delete:
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

        Try
            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
                Me.DetailsBindingNavigator2.BindingSource.RemoveCurrent()
            End If

            Me.Validate()
            Me.DetailsBindingSource2.EndEdit()
            Me.TableAdapterManager2.UpdateAll(Me.DataSet3)
         
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


This post has been edited by maiOHmai: 28 September 2012 - 10:36 PM

Was This Post Helpful? 0
  • +
  • -

#9 Jemmeh  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 20-March 10

Re: problem in delete button on BindingNavigator

Posted 07 October 2012 - 10:22 AM

So I did a XML binding navigator a while back and I think you can do it the same way where you just accept the changes to the data on form close. I made a video on how that was done:
http://www.youtube.c...bg&feature=plcp

And then in the delete button clicked event do something to the tune of this pseudo-code:

Messagebox.Show("Are you sure you want to delete?")
If no is pressed:
cancel the event args (basically act like the delete button was never pressed)
exit sub
end if


To fix your code:
I'm not sure in your code how the current item is being selected.I would debug.print to see what the current selected item is and if it says nothing you need to be giving it some way to select the current item--that would be my guess based on the error message, anyways.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1