C# 用dataGridView和DataTable显示列表,新增一列时在数据上方出现空行
尝试过将AllowUserToAddRows属性改为Flase,无果
public DataTable table = new DataTable("Product");
private void button1_Click_1(object sender, EventArgs e)
{
DataColumn column1 = new DataColumn();
column1.DataType = System.Type.GetType("System.Object");
column1.ColumnName = "边长";
table.Columns.Add(column1);
foreach (double bian in mDistance)
{
DataRow row;
row = table.NewRow();
row["边长"] = bian;
table.Rows.Add(row);
}
DataColumn column2 = new DataColumn();
column2.DataType = System.Type.GetType("System.Object");
column2.ColumnName = "观测角";
table.Columns.Add(column2);
foreach (double guanjiao in mAngle)
{
DataRow row2;
row2 = table.NewRow();
row2["观测角"] = guanjiao;
table.Rows.Add(row2);
}
dataGridView1.DataSource = table;
}