Jumat, 29 Oktober 2010

Delete row in DataGridView

we will discuss how to delete a row in DataGridView. its very easy way of typing the following syntax:
Private Sub DataGridView1_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles DataGridView1.UserDeletingRow
  Dim id As String = e.Row.Cells("ISBN").FormattedValue.ToString() 'Taking value to the ISBN field
  Dim name As String = e.Row.Cells("Title").FormattedValue.ToString()
'Displays a dialog windows
Dim result As DialogResult = MessageBox.Show("Are you sure you want to delete ISBN " & id & " - " & name & "?", "Delete?", MessageBoxButtons.OKCancel)
'If the Cancel button that is selected then the process will be deleted.
If result = DialogResult.Cancel Then
e.Cancel = True
End If