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

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

关于c# - 访问单元格datagridview Winform C#的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8871423/

相关文章:

C# - 如何从数据表中获取标题行并将其垂直排列在一列中?

c# - C# 中的对象存储

c# - 在控制深度的同时遍历目录 - C#

.net - MenuStrip 控件能否将其 LayoutStyle 设置为 StackWithOverflow?

c# - RichTextBox 替换 Winforms .NET2.0+

database - VB.NET - .accdb 数据库不保存更改

c# - SSRS 以编程方式设置 "Credentials stored securely in the report server"

c# - 在 C# 中强制方法等待计时器停止

c# - 如何防止用户控件填充选项延伸太远

c# - DataTable 与 DataGridView 的奇怪行为