地狱的家伙我有一个datagridview
,其中我的列很少,其中一个是e-mail
,另一个是CheckBoxcolumn
,名为check
(第3列)。现在我有一个字符串receivers
,我需要用所有值填充此字符串,其中行是复选框列,因此我想出了这个(工作):
String prijemci;
foreach (DataGridViewRow row in dtg_korespondence.Rows)
{
if (Convert.ToBoolean(row.Cells[4].Value) == true)
{
receivers = ; // need to fill this string with all values from column "e-mail" separeted by ";"
}
}
数据网格视图由SqlServer
通过名为DataTable
的{{1}}填充。
因此输出结果如下:firstmail@provider.com; secondmail@provider.com
请有人帮我解决这个问题吗?
提前致谢
答案 0 :(得分:2)
String prijemci;
foreach (DataGridViewRow row in dtg_korespondence.Rows)
{
if (Convert.ToBoolean(row.Cells[4].Value) == true)
{
receivers += row.Cells["e-mail"].Value.ToString()+";"; // need to fill this string with all values from column "e-mail" separeted by ";"
}
}
我希望这有帮助,除非你想直接从DataTable dt2
答案 1 :(得分:2)
receivers = string.Join(";", dtg_korespondence.Rows.OfType<DataGridViewRow>()
.Where(r=>Convert.ToBoolean(r.Cells[4].Value))
.Select(r=>r.Cells["e-mail"].Value.ToString()));