Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 删除datagridview中带有for each misses-up索引的行,使其跳过行_Vb.net_Datagridview_Foreach - Fatal编程技术网

Vb.net 删除datagridview中带有for each misses-up索引的行,使其跳过行

Vb.net 删除datagridview中带有for each misses-up索引的行,使其跳过行,vb.net,datagridview,foreach,Vb.net,Datagridview,Foreach,我目前正在将我的项目从listview更改为datagridview,并且在尝试删除以x字符串开头的行时遇到了另一个“问题” For Each itm As DataGridViewRow In DataGridView1.Rows If Not itm.Cells(0).Value.StartsWith(myValue) Then DataGridView1.Rows.Remove(itm) End If Next 因此,是的,我得出的结论是,它以某种方式弄乱了索引或foreach,

我目前正在将我的项目从listview更改为datagridview,并且在尝试删除以x字符串开头的行时遇到了另一个“问题”

For Each itm As DataGridViewRow In DataGridView1.Rows
If Not itm.Cells(0).Value.StartsWith(myValue) Then
    DataGridView1.Rows.Remove(itm)
End If
Next

因此,是的,我得出的结论是,它以某种方式弄乱了索引或foreach,因为它删除了一行后,它会跳过下一行,如果这有意义的话。

你完全正确。从列表对象中删除项目时,始终使用步骤-1从最后一项枚举到第一项,这将始终有效。是的,我现在已经学会了,谢谢:)我在42年前的大学里学会了这一点。