简体   繁体   English

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

[英]Access the content of a cell datagridview Winform C#

Hello so I managed to get the row where my mouse highlighted it. 你好,所以我设法得到我的鼠标突出显示它的行。 However I don't know how to access its content. 但是我不知道如何访问其内容。

for example: I highlighted row 25 I can get that it highlighted row 25 howver I don't know how to access its content and put it all in a textbox. 例如:我突出显示第25行我可以得到它突出显示第25行我怎么不知道如何访问其内容并将其全部放在文本框中。 anyone? 任何人?

you can use the value property to access the content of the cell as follows 您可以使用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

To do exactly what you are asking something like this should suffice 要完全按照你的要求做这样的事就足够了

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM