Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView Deleting Selected rows...

Status
Not open for further replies.

Tim8w

Programmer
Apr 8, 2003
44
0
0
US
This is such a basic question, I'm almost emvbarassed to ask it. How do I loop through seleted rows in a DataGridView and remove the rows?

I've tried this, but it doesn't work. After one row is removed, the index is all screwed up...

Code:
            iIndex = dgvRecipe.Rows.GetNextRow(-1, DataGridViewElementStates.Selected)
            While iIndex <> -1
                dgvRecipe.Rows.RemoveAt(iIndex)
                iIndex = dgvRecipe.Rows.GetNextRow(iIndex, DataGridViewElementStates.Selected)
            End While
 
As jwavila reminded me on another forum...

Code:
For iIndex = dgvRecipe.RowCount - 1 To 0 Step -1
    dgvRecipe.Rows.RemoveAt(iIndex)
Next iIndex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top