0

伙计们,我有一个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 ";" 
            }
        }

SqlServerdatagridview通过DataTable命名填充dt2

所以输出看起来像:firstmail@provider.com;secondmail@provider.com

有人可以帮我解决这个问题吗?

提前致谢

4

2 回答 2

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

于 2013-09-17T14:26:58.110 回答
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()));
于 2013-09-17T14:41:23.460 回答