You are resetting the text instead of appending the comma in the if loop. Your code in the if block should be.
if (!firstvalue)
{
textBox1.Text += ",";
}
UPDATE SM:
Try:
if (!firstvalue)
{
textBox1.Text += "," + dataGridView1.SelectedCells[1].Value.ToString();
}
Update #2 Tarak:
Another problem is you are resetting the textBox1.Text = "" for each of the row. You have to move it out of the foreach. Also you need to use the drv and get the value from that.
private void btnUpdate_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows != null)
{
textBox1.Text = "";
bool firstvalue = true;
foreach (DataGridViewRow drv in dataGridView1.SelectedRows)
{
if (!firstvalue)
{
textBox1.Text += ",";
}
textBox1.Text += drv.Cells[1].Value.ToString();
firstvalue = false;
}
}
}