Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
' start process
Cursor = Cursors.AppStarting
' prepare variables
Dim dr As DialogResult
Dim id As Integer
Dim code As String
Dim name As String
Dim message As String
Dim pos As Integer
' ambil id dan code dari data yg akan diedit
Dim dv As DataRowView
dv = Me.BindingContext(Me.ItemsBindingSource).Current
id = Convert.ToInt32(dv("id"))
code = Convert.ToString(dv("code"))
name = Convert.ToString(dv("name"))
' buat pesan konfirmasi
message = String.Format("Are you sure to delete this [{0}] {1} data ? ", code, name)
' try deleting
Try
dr = MessageBox.Show(message,
Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If dr = Windows.Forms.DialogResult.Yes Then
pos = Me.BindingContext(Me.ItemsBindingSource).Position
Me.BindingContext(Me.ItemsBindingSource).RemoveAt(pos)
Me.ItemsTableAdapter.Update(Me.DsInventory)
Me.DsInventory.AcceptChanges()
End If
Catch ex As Exception
MessageBox.Show("Error deleting data from database\nDetails: " + ex.Message,
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Me.DsInventory.RejectChanges()
End Try
' finish up
Cursor = Cursors.Default
End Sub