Solved

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

Posted on 2013-01-29
2
894 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

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

Featured Post

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

628 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