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

Recommended Answers

All 2 Replies

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.