我想在数据网格视图中的特定单元格中设置文本。我使用DataGridViewTextBoxColumns填充网格视图。有人可以帮忙吗?
这里我设置了DataGridViewTextBoxColumn
private void setUpGridTableForGridView(int rows, int columns)
{
for (int i = 0; i < columns;i++ )
{
DataGridViewTextBoxColumn dgc = new DataGridViewTextBoxColumn();
RunTimeCreatedDataGridView.Columns.Add(dgc);
}
for (int i = 1; i < rows;i++ )
{
RunTimeCreatedDataGridView.Rows.Add();
}
}
答案 0 :(得分:0)
您可以按行和列索引访问任何网格单元格:
int row = 0;
int column = 0;
RunTimeCreatedDataGridView[column, row].Value = "hello world";
// or
RunTimeCreatedDataGridView.Rows[row].Cells[column].Value = "hello world";
您也可以添加值包含的行:
for (int i = 1; i < rows;i++ )
{
RunTimeCreatedDataGridView.Rows.Add(string.Format("row{0} column 0", i), string.Format("row{0} column 1", i));
}