访问单元格的内容datagridview Winform C#

访问单元格的内容datagridview Winform C#,c#,winforms,datagridview,C#,Winforms,Datagridview,你好,所以我设法找到了鼠标突出显示的那一行。但是我不知道如何访问它的内容 例如:我突出显示了第25行,我可以得到它突出显示了第25行,但我不知道如何访问它的内容,并把它全部放在一个文本框中。有人吗?您可以使用value属性访问单元格的内容,如下所示 // the content of the cell var x = dataGridView1.Rows[0].Cells[0].Value; // this gets the content of the first selected cell

你好,所以我设法找到了鼠标突出显示的那一行。但是我不知道如何访问它的内容


例如:我突出显示了第25行,我可以得到它突出显示了第25行,但我不知道如何访问它的内容,并把它全部放在一个文本框中。有人吗?

您可以使用value属性访问单元格的内容,如下所示

// the content of the cell
var x = dataGridView1.Rows[0].Cells[0].Value;

// this gets the content of the first selected cell 
dataGridView1.SelectedCells[0].Value;

// you can set the cells the user is able to select using this 
dataGridView1.SelectionMode= SelectionMode. //intellisense gives you some options here
完全按照你的要求去做,像这样的事情就足够了

System.Text.StringBuilder t = new System.Text.StringBuilder();
String delimiter = ",";

foreach(DataGridViewCell c in dataGridView1.SelectedRows[0].Cells)
{
    t.Append(c.Value);
    t.Append(delimiter);
}

textBox1.Text = t.ToString();

请发布您尝试过的代码。
网格[j,i].Value.ToString()
可能也可以访问它。我认为
网格[j,i]
非常紧凑。非常感谢您,先生!我会用这个,如果有用的话会给你更新。非常感谢,先生!这真的帮了我很大的忙。我很欣赏你先举例,而不是仅仅给出答案,这样我就可以很容易地理解。谢谢:))如何访问dataGridView1变量?你在什么地方申报了吗?