你好,我成功地获取了鼠标所选中的行。但是我不知道如何访问它的内容。
例如:我选择了第25行,我可以知道它选择了第25行,但我不知道如何访问它的内容并将其放入文本框中。有人能帮忙吗?
你好,我成功地获取了鼠标所选中的行。但是我不知道如何访问它的内容。
例如:我选择了第25行,我可以知道它选择了第25行,但我不知道如何访问它的内容并将其放入文本框中。有人能帮忙吗?
// 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();
theGrid[j, i].Value.ToString()
可能也会访问它,我认为theGrid[j, i]
相当简洁。 - barlopdataGridView1[columnIndex, rowIndex].Value.ToString()
只是为了澄清索引的位置。 - Luis Almeida