2

I have a datagridview with a column "name". There are about 50 rows with names. I would like to get all the names in one delimited sting, like this "David, john, Kim". Do I have to loop on all the rows in the grid for this or there is something cleaner without looping?

I'm using framework 4.0, c# winforms.

Thanks.

Itay.B
  • 3,991
  • 14
  • 61
  • 96

1 Answers1

1

with help of LINQ:

string names = string.Join(", ", grid.Rows.OfType<DataGridViewRow>()
               .Select(i => i.Cells["name"].Value.ToString()).ToArray())
EgorBo
  • 6,120
  • 3
  • 35
  • 40