繁体   English   中英

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

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

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

例如:我突出显示第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();

暂无
暂无

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

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