Solved

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

Posted on 2013-01-29
2
889 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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