-1

我正在遍历 DataGridView 中的行,如下所示:

For Each orow As DataGridViewRow In GV_NS.Rows
    If orow.Cells(0).Value.Length = 0 Then
        //Skip this row and go to next row
    Else
        //do this
    End If
Next

如果第一列为空,我希望能够跳到下一行。我尝试只使用Nextin If orow.Cells(0).Value.Length = 0,但它抛出了语法错误If must end with matching End If。有什么建议么?

4

3 回答 3

1

要跳到、 或循环的下一次迭代,For请像这样使用:DoWhileContinue

For Each orow As DataGridViewRow In GV_NS.Rows
    If orow.Cells(0).Value.Length = 0 Then
        //Skip this row and go to next row
        Continue For
    Else
        //do this
    End If
Next
于 2012-11-20T16:55:19.027 回答
1

您也可以只反转您的测试。

For Each orow As DataGridViewRow In GV_NS.Rows
    If orow.Cells(0).Value.Length <> 0 Then
        //do this
    End If
Next
于 2012-11-20T17:06:47.190 回答
0
    'Filter rows with LINQ
    Dim Query = From row In GV_NS.Rows
        Where CType(row, DataGridViewRow).Cells(0).Value.ToString.Length > 0
        Select row
    For Each Row As DataGridViewRow In CType(Query.ToArray, DataGridViewRow())
        'Do something
    Next
于 2012-11-21T06:01:27.623 回答