Remove/Delete row from DataGridView

How I can remove/delete row or set of rows from DataGridView ?
ty-exexch-koAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SAMIR BHOGAYTATeam LeadCommented:
Hello,

Write code in rowdeleting event of a gridview. or use this code.

http://www.codeproject.com/KB/webforms/GridViewConfirmDelete.aspx
CodeCruiserCommented:
You can use the .Rows.Remove either in the DataGridView or the DataTable which is being used as the datasource.
ty-exexch-koAuthor Commented:
I want to know how delete row of DataGridView in Vb.NET
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

CodeCruiserCommented:
That's what I said above.
Anurag AgarwalCommented:
try this

Use the Rows collection's Remove or RemoveAt method. The following code checks to see if the current row is new because you cannot delete a new row. It then removes the current row.  
 
Private Sub btnDelete_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnDelete.Click
    If Not DataGridView1.CurrentRow.IsNewRow Then
        DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
    End If
End Sub


You select the entire row by clicking the header on the right of the DataGridView.
Then  you can use the following code to remove a row(s) from the control. You can select more than one row for deletion at a time.

// remove all rows selected  
 For Each dr As DataGridViewRow In DataGridView1.SelectedRows
      If DataGridView1.Rows.Count > 1 Then
            DataGridView1.Rows.Remove(dr)
      End If
Next

 
Shahan AyyubSenior Software EngineerCommented:

To delete all rows:
DataGridView1.Rows.Clear()

To delete Selected ROW:
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)

To delete Selected ROWS:
        For i As Integer = 0 To DataGridView1.SelectedRows.Count - 1
            DataGridView1.Rows.Remove(DataGridView1.SelectedRows(0))
        Next

ty-exexch-koAuthor Commented:
Thanks for all answers

I need for example to delete the 2nd row from Datagridview without select the row ?
Anurag AgarwalCommented:
hi ty-exexch-ko,
'Remove the 2nd row down as

DataGridView1.Rows.RemoveAt(1)

'row counting starts at zero.
you can write this on click of button or any function call, just give the index number(less than one as row count starts from 0) of the row you want to delete .


Happy new year!!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.