The MSDN documentation says of the DataGridViewRow.Selected property:
Is that actually what you want to do, set whether the row is selected or not? Obviously not, as you say that you want to set the value of a field in that row.
Gets or sets a value indicating whether the row is selected.
A quick look at the MSDN help topic for the DataGridViewRow member listing shows the Cells property, described thusly:
Hmmm... that sounds like it might be useful, given that you want to set the value of a cell in that row.
Gets the collection of cells that populate the row.
Clicking on the property name, which is a link, takes us to the Help topic for that property. It has an Example section that says this:
and provides this code example:
The following code example uses the Cells property to set the value of a cell in the row
. This code example is part of a larger code example provided in How to: Manipulate Rows in the Windows Forms DataGridView Control.
Who would have thought the Help could be so helpful? Perhaps it could even help someone without a comprehensive understanding of VB to gain that understanding. It might even help them learn things that they weren't even looking for.
' Give cheescake excellent rating.
Private Sub Button8_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button8.Click
Private ratingColumn As Integer = 3
Private Sub UpdateStars(ByVal row As DataGridViewRow, _
ByVal stars As String)
row.Cells(ratingColumn).Value = stars
' Resize the column width to account for the new value.