Datagridview

时间:2016-09-15 10:02:30

标签: vb.net datagridview

我的代码出了什么问题?

   If DataGridView1.Rows.Count = 0 Then
            MsgBox("Nothing to save.")
        Else
            For Each row As DataGridViewRow In DataGridView1.Rows

                If row.Cells(5).Value.ToString() = "" Then
                    row.Cells(0).Value = True

                    MsgBox("Please indicate your adjustment reason")
                Else
                    final_save()
                End If
            Next

        End If

我阻止用户在datagridview的第5列保存部分或全部单元格的数据。上面的代码正在运行,但是对于它找到的每一行都重复该消息

TYSM未来的帮助

1 个答案:

答案 0 :(得分:0)

你没有退出循环。尝试使用Exit For。如果所有行都通过测试,您也应该保存。

       dim failed = false
       For Each row As DataGridViewRow In DataGridView1.Rows

            If row.Cells(5).Value.ToString() = "" Then
                row.Cells(0).Value = True

                MsgBox("Please indicate your adjustment reason")
                failed = true
                Exit for

            End If
        Next
        if not failed then final_save()