As a side note this might work for your original code:
if (dataGridView1.Rows[e.RowIndex].Index != -1)
{
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
else
{
textBox1.Text = "";
}
Edit: You'd think I could've put all that in one response, but noo... I had to go and TEST stuff between hand lol