This works:
DataGridView.Rows.Add("Bla Bla Bla", value1, value2)
But if I do:
Dim newrow As New DataGridViewRow
newrow.SetValues("Bla Bla Bla", value1, value2)
If Not value1.Equals(value2) Then
newrow.DefaultCellStyle.ForeColor = Color.Red
End If
DataGridView.Rows.Add(newrow)
the entire row is empty.
Why is the row full of empty cells?
Your
newrowvariable does not have any cells, andSetValuesis ignoring your information because there aren’t any cells to set values to.From DataGridViewRow.SetValues Method:
Use the
CreateCellsmethod to populate the cells: