正如问题所说,是否有可能删除a到b中的行我尝试过像这样的事情
Dim dgv As DataGridViewRowCollection = DataGridView1.Rows
For Each rw As DataGridViewRow In dgv
Console.WriteLine(rw.Index)
If (rw.Index > iNbrRow) Then
If (Not rw.IsNewRow) Then
Console.WriteLine("Delete : " & rw.Index)
'dgv.RemoveAt(rw.Index)
End If
End If
Next
但问题是每次删除一行时索引都会改变,所以它会删除所有这些
P.S:iNbrRow =行数 - 2在表单加载时初始化
谢谢你希望你们能帮忙:S
答案 0 :(得分:2)
如果从gridview的末尾开始并向后退,则不会发生这种情况:
For i As Integer = gView1.Rows.Count-1 To 0 Step -1
If i > iNbrRow then
' delete the row
end if
Next i