📜  vb.net 以编程方式将行添加到 datagridview - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:59.437000             🧑  作者: Mango

代码示例3
DataTable dt = new DataTable();

// first add your columns
for (int i = 0; i < count; i++)
{
    dt.Columns.Add(fromFileFields[i]);
}

// and then add your rows
for (int i = 0; i < count; i++)
{
    var row = dt.NewRow();
    // Set values for columns with row[i] = xy
    dt.Rows.Add(row);
}

datagridview.DataSource = dt;