1

我正在创建一个程序,该程序保存客户详细信息并向他们发送电子邮件,提醒他们特别优惠。我在导出电子邮件数据时遇到问题,因为我想将其存储在sendto.text用逗号分隔每个地址的字段中,如何从每一行获取数据,datagrid并且可以将其存储并用逗号分隔textfield吗? .

希望这是有道理的。谢谢

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    sendto.text = dataGridView1.Rows[i].Cells[3].Value.ToString());
}
4

4 回答 4

4

像这样?:

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    sendto.text += dataGridView1.Rows[i].Cells[3].Value.ToString() + (i < (dataGridView1.Rows.Count-1) ? "," : "");
}
于 2013-11-08T13:41:05.223 回答
3
   StringBuilder stremail = new StringBuilder();

   for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        stremail.Append(dataGridView1.Rows[i].Cells[3].Value.ToString() + ",");
    }

    int stringWithoutLastComma = --stremail.Length;
    sendto.text = stremail.ToString(0,stringWithoutLastComma);
于 2013-11-08T13:45:32.607 回答
3

您可以从第二个 emailid 开始添加逗号。

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    if(i>0)
        sendto.text +=","+ dataGridView1.Rows[i].Cells[3].Value.ToString());
    else
        sendto.text = dataGridView1.Rows[i].Cells[3].Value.ToString());
}
于 2013-11-08T13:41:32.443 回答
2

你可以:

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    sendto.text += string.Format("{0},", dataGridView1.Rows[i].Cells[3].Value.ToString());
}
于 2013-11-08T13:42:14.763 回答