Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对于每个选定的datagridview行,发送到richTextBox_C# - Fatal编程技术网

C# 对于每个选定的datagridview行,发送到richTextBox

C# 对于每个选定的datagridview行,发送到richTextBox,c#,C#,我需要foreach选定的datagridview1行将特定单元格发送到richTextBox foreach (DataGridViewRow item in this.dataGridView1.SelectedRows) { //Each foreach iteration, item will contain a different row. richTextBox1.Text += item.Cells[1].Value.ToString(); //Append the

我需要foreach选定的datagridview1行将特定单元格发送到richTextBox

foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
{
    //Each foreach iteration, item will contain a different row.
    richTextBox1.Text += item.Cells[1].Value.ToString(); //Append the text of the current row
}
以下是我正在尝试的:

 foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
                {
                 richTextBox1.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

但它只适用于第一个选中的项目。

对于要重置richTextBox1内容的每个项目

在您的foreach中,您应该使用“item”。当前未使用项,但始终使用第一行

您可能希望将文本附加到RichTextBox的内容中

foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
{
    //Each foreach iteration, item will contain a different row.
    richTextBox1.Text += item.Cells[1].Value.ToString(); //Append the text of the current row
}

注:something+=x是something=something+x的缩写

使用
项而不是
dataGridView1.SelectedRows[0]
?另外,不要使用
=
而是
+=
来避免每次迭代都覆盖文本框的文本?