0
 Dim i1 As Integer
        Dim i2 As Integer
        For i1 = 0 To Me.DataGridView5.Columns.Count - 1
            For i2 = 0 To Me.DataGridView5.Rows.Count - 1
                If String.IsNullOrEmpty(Me.DataGridView5.Item(i1, i2).Value) Then
                    MessageBox.Show("You must fill in all cells before you can save the data.", "Empty Cells", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    DataGridView5.Rows(i1).Cells(i2).Style.BackColor = Color.Bisque  'Index was out of range. Must be non-negative and less than the size of the collection.
                    Exit Sub
                    'MessageBox.Show(String.Format("{0},{1}", i1, i2)
                End If
            Next
        Next
2
Contributors
2
Replies
12
Views
4 Years
Discussion Span
Last Post by ddanbe
0

i want to check empty cells in datagrid view when button clicked and change its color but i find this error..

0

Line 7: you pass i1 to the Rows collection, i1 is the column counter.
Perfect example of giving sensible names to your counter variables. If you named i1, "col" or something you would not have made that mistake.
Hope I helped you out!

Edited by ddanbe: addition

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.