2016-09-15 4 views
0

私のコードで何が間違っていますか?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番目の列にある一部またはすべてのセルのデータを保存するユーザーを停止しています。上記のコードは機能していますが、メッセージには、それはあなたがループを出ていない将来の助けを

答えて

0

TYSMを見つけた空の行ごとに繰り返されます。 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() 
+0

TYSM –