Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-29
2
Medium Priority
?
897 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
[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 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

722 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