Not true: your code does not return anything. This is a method (Sub), probably used as an event handler; it does not return anything but uses some
side effect, which is the assignment of some string value to
TextBox1.Text
(never ever use such names; never ever use auto-generated names which comes from the designer; they violate Microsoft naming conventions and does not carry any semantic meaning; always renames all such members).
Please see the comment to the question by Wes Aday. This is all you need to know.
Now, your loop is totally pointless. It's effect is equivalent to just one assignment:
TextBox1.Text = DataGridView1.Rows(DataGridView1.RowCount - 1).Cells(0).ToString()
As to the values you assigned on all the iterations of your loop, they are all lost (all but one),
because you replace it with the value in next iteration. Only the value in the very last iterations remains in the value of
TextBox1.Text
. Isn't that obvious. And, if your observations are correct, the values assigned in last iteration is empty string. Perhaps this is just a cell with not yet entered data. As simple as that.
That's all.
—SA