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 newrow
variable does not have any cells, and SetValues
is ignoring your information because there aren't any cells to set values to.
From DataGridViewRow.SetValues Method:
If there are more values in the values list than there are cells to be initialized, this method ignores the extra values and returns false. This method also returns false if any of the specified values cannot be set.
If there are fewer values than there are cells, the remaining unmatched cells retain their current values.
Use the CreateCells
method to populate the cells:
newrow.CreateCells(DataGridView)
'' or
newrow.CreateCells(DataGridView, New Object() {"Bla Bla Bla", value1, value2})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With