Delete Multiple rows from datagridview

前端 未结 2 1414
离开以前
离开以前 2020-12-22 06:28

I\'ve a datagridview in which values are inserted.The gridview is like this.

    Item                PRID                 
   ------              ------              


        
2条回答
  •  旧巷少年郎
    2020-12-22 06:57

    The are a couple of ways around this. One is to do the following

    for (int i = dataGridView1.RowCount - 1; i >= 0; i--)
        if (String.Compare(dataGridView1.Rows[i].Cells[1].Value.ToString(), "2") == 0)
            dataGridView1.Rows.Remove(dataGridView1.Rows[i]);
    

    This is looping from the bottom end of the DataGridView and avoids the problem with removing rows whilst iterating.

    I hope this helps.

提交回复
热议问题