开发者

DatagridView concat strings

开发者 https://www.devze.com 2023-03-17 11:24 出处:网络
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\".

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.


with help of LINQ:

string names = string.Join(", ", grid.Rows.OfType<DataGridViewRow>()
               .Select(i => i.Cells["name"].Value.ToString()).ToArray())
0

精彩评论

暂无评论...
验证码 换一张
取 消