C# 如何将新添加的行移动到DataGridView的拓扑中?
C# 如何将新添加的行移动到DataGridView的拓扑中?,c#,winforms,datagridview,C#,Winforms,Datagridview,datagridview1.Add()将向datagridview添加新行,但它将被放置在所有行的底部。但是如何将这个新添加的行移动到其中所有行的顶部呢 谢谢尝试通过插入新项目来添加新项目: dataGridView1.Rows.Insert(0, item) 您不能直接操作gridview的数据源 相反,您可以使用IList集合并使用插入方法,例如 IList<Product> source = new List<Product>(); /// populate so
datagridview1.Add()
将向datagridview
添加新行,但它将被放置在所有行的底部。但是如何将这个新添加的行移动到其中所有行的顶部呢
谢谢尝试通过插入新项目来添加新项目:
dataGridView1.Rows.Insert(0, item)
您不能直接操作gridview的数据源 相反,您可以使用IList集合并使用插入方法,例如
IList<Product> source = new List<Product>();
/// populate source with products
///
source.Insert(0, new Product("Table"));
this.dataGridView1.DataSource = source;
IList source=new List();
///用产品填充源
///
来源。插入(0,新产品(“表格”);
this.dataGridView1.DataSource=source;