Results 1 to 5 of 5

Thread: To delete selected row from datagridview control.

  1. #1
    Join Date
    Jan 2009
    Posts
    19

    To delete selected row from datagridview control.

    HI,
    I want a code that will enable me to delete a selected row from my DataGridView control in my vb.net application.

    Any help!

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: To delete selected row from datagridview control.

    Deleting Rows
    To programmatically delete a row in the DataGridView control, you can use the Remove() method. The following code snippet removes all the selected rows in the DataGridView control:


    Code:
            For Each row As DataGridViewRow In DataGridView1.SelectedRows
                DataGridView1.Rows.Remove(row)
            Next
    The user can also delete rows by first selecting the rows and then pressing the Delete key. By default, the deletion is done automatically without any prompting. But you may want to confirm the deletion with the user before deleting them. You can do so via the UserDeletingRow event:


    Code:
        Private Sub DataGridView1_UserDeletingRow( _
           ByVal sender As Object, _
           ByVal e As System.Windows.Forms. _
           DataGridViewRowCancelEventArgs) _
           Handles DataGridView1.UserDeletingRow
            If (Not e.Row.IsNewRow) Then
                Dim response As DialogResult = _
                MessageBox.Show( _
                "Are you sure you want to delete this row?", _
                "Delete row?", _
                MessageBoxButtons.YesNo, _
                MessageBoxIcon.Question, _
                MessageBoxDefaultButton.Button2)
                If (response = DialogResult.No) Then
                    e.Cancel = True
                End If
            End If
        End Sub

  3. #3
    Join Date
    May 2008
    Posts
    115

    Re: To delete selected row from datagridview control.

    Use the Remove method, providing it with the index of the selected row.

    Code:
    DataGridView1.Rows.Remove(DataGridView1.CurrentRow)

  4. #4
    Join Date
    Sep 2011
    Posts
    1

    Re: To delete selected row from datagridview control.

    hey guys, i done this the data is geting deleted but not updating in database........ am using access database .....anybody please help out .............

  5. #5
    Join Date
    Jan 2012
    Posts
    1

    Re: To delete selected row from datagridview control.

    hey guys, I've done this the data is getting deleted in the grid but not updating in database........ am using SQL Management Studio 2008...plz help guys

Similar Threads

  1. Replies: 3
    Last Post: 06-01-2014, 11:07 AM
  2. Replies: 6
    Last Post: 29-03-2012, 02:56 PM
  3. Replies: 5
    Last Post: 10-01-2011, 08:54 AM
  4. cannot delete selected text in Office Word 2003
    By WarHammer in forum Windows Software
    Replies: 6
    Last Post: 13-02-2009, 11:42 PM
  5. disable control-alt-delete using C#
    By Vireshh in forum Software Development
    Replies: 4
    Last Post: 08-01-2009, 08:53 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,023,074.84019 seconds with 16 queries