Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

URGENT! VB.NET -- Need to Delete DataGridViewRow from both DataSet and Database with BindingNavigatorDeleteItem

Posted on 2013-01-29
2
Medium Priority
?
901 Views
Last Modified: 2013-02-14
Hi everyone,

Is there a way to enable a BindingNavigatorDeleteItem on a BindingNavigator to simultaneously delete a row from the dataset and the underlying data source?

I want to modify the current behavior which involves clicking the BindingNavigatorDeleteItem then clicking the Table1BindingNavigatorSaveItem to make it permanent.

Thanks!
0
Comment
Question by:Eric Burton
2 Comments
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 1000 total points
ID: 38833810
Try This In You BindingNavigatorDeleteItem.Click Event
Try

            If Me.MyDataGridView.Rows.Count < 1 Then
                Exit Sub
            Else
                If Not MyDataGridView.CurrentRow Is Nothing Then
                  
                          Me.Cursor = Cursors.WaitCursor
                            Dim selRow As DataGridViewRow = MyDataGridView.CurrentRow
                            MyDataGridView.Rows.Remove(selRow)
                         Me.Cursor = Cursors.Default
                End if
           End If
 Catch ex As Exception
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Me.Cursor = Cursors.Default
End Try

Open in new window

Then In Table1BindingNavigatorSaveItem.Click
Try
 Me.Cursor = Cursors.WaitCursor
            If MyDataSet.HasChanges Then
                                Dim ItemDelete() As DataRow = MyDataSet.MyDataTable.Select("", "", DataViewRowState.Deleted)
                                Me.MyTableAdapter.Update(ItemDelete)
                                MessageBox.Show("Done....!!!!(Row deleted)", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information)
                                Me.Cursor = Cursors.Default
 Catch ex As Exception
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Me.Cursor = Cursors.Default
End Try

Open in new window

And something more ...
add also this to your Code to save new and edit data in your Database
 Dim ItemInsert() As DataRow = MyDataSet.MyDataTable.Select("", "", DataViewRowState.Added Or DataViewRowState.ModifiedCurrent)
 Me.MyTableAdapter.Update(ItemInsert)

Open in new window

Hope that Helps
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 38834362
Copy the Update call from your save method to delete method.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question