Solved

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

Posted on 2013-01-29
2
871 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:eq2006
2 Comments
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 250 total points
Comment Utility
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 250 total points
Comment Utility
Copy the Update call from your save method to delete method.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now