从for循环到以逗号分隔的消息框的值 [英] Values from a for loop to a message box separated with comma
本文介绍了从for循环到以逗号分隔的消息框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想把一个for循环的值用逗号分隔到一个消息框。
下面是我的for循环。
Hi,
I want to get the values from a for loop separated with comma in to a single message box.
Below is my for loop.
for (int i = 0; i < dtgrdUnconfirm.Rows.Count; i++)
{
DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)dtgrdUnconfirm.Rows[i].Cells[0];
if (ch1.Value != null &&
Convert.ToBoolean(ch1.Value) == true)
{
data = (dtgrdUnconfirm.Rows[i].Cells[6].Value.ToString());
}
}
在这个for循环中,字符串数据会得到4个值,我希望这4个值显示在用逗号分隔的单个消息框中。例如,输出应为1,2,3,4
先谢谢
In this for loop, string data will get 4 values and I want those 4 values to be shown in a single message box separated with comma. For example, output should be 1,2,3,4
Thanks in advance
推荐答案
我刚修改了你的代码
Hi,
I just modified your code
for (int i = 0; i < dtgrdUnconfirm.Rows.Count; i++)
{
DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)dtgrdUnconfirm.Rows[i].Cells[0];
if (ch1.Value != null &&
Convert.ToBoolean(ch1.Value) == true)
{
data += (dtgrdUnconfirm.Rows[i].Cells[6].Value.ToString())+",";
}
}
MessageBox.Show(data);
这篇关于从for循环到以逗号分隔的消息框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文