want to get value of cell 0 of selected rows in 2 text boxes
Your code does almost opposite. You are comparing cell value with textbox text and doing some operation.
You need to do something like:
string str = dataGridView1.Rows[i].Cells.Value.ToString() + '-' + str;