Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27201

Trying to delete a row from a bound DataGridView?

$
0
0
I'm trying to delete a row from a bound DataGridView using the code below. It seems to work when I click the last button, which by the way I can't seem to get the text on). Anyway, it removes the row but when I close the form and then reopen it, the data is still there. Here is my code below as well as screenshot.

Code:

    Private Sub dgvTrans_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTrans.CellClick
        Try
            Select Case e.ColumnIndex
                Case 6
                    If Me.Validate() Then
                        Me.bsTrans.EndEdit()
                        TransactionsTableAdapter.Update(BudgetDataSet8.Transactions)
                        BudgetDataSet8.Transactions.AcceptChanges()
                        MessageBox.Show("Record Updated!", "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Case 7
                    If Me.Validate() Then
                        Me.bsTrans.EndEdit()
                        BudgetDataSet8.Transactions.Rows(e.RowIndex).Delete()
                        BudgetDataSet8.Transactions.AcceptChanges()
                        MessageBox.Show("Record Deleted!", "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
            End Select

        Catch ex As Exception
            Dim strErr As String = "frmTransactions/dgvTrans_CellClick() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Attached Images
 

Viewing all articles
Browse latest Browse all 27201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>