如何向未绑定的 devexpress GridControl 添加新行?

How to add new row to unbound devexpress GridControl?

我已经创建了网格控件并在设计器中添加了 4 列(BS、Repere、Profil、Quantity),我想通过单击按钮添加新行,所以我使用此代码:

gridView2.AddNewRow();    
                    gridView2.SetRowCellValue(GridControl.NewItemRowHandle, gridView2.Columns["BS"], rowGridView1["BS"]);
                    gridView2.SetRowCellValue(GridControl.NewItemRowHandle, gridView2.Columns["Repere"], rowGridView1["Repère"]);
                    gridView2.SetRowCellValue(GridControl.NewItemRowHandle, gridView2.Columns["Profil"], rowGridView1["Profil"]);
                    gridView2.SetRowCellValue(GridControl.NewItemRowHandle, gridView2.Columns["Quantity"], quantity.EditValue);

但是当我 运行 代码没有任何反应时,我的网格控件没有绑定到任何类型的数据,我该如何解决这个问题? , 在此先感谢。

声明一个 class 来保存单个行的数据

class GridRow 
{
   public string BS { get; set;}
   public string Repere { get; set; }
   public string Profil { get; set; }
   public int Quantity { get; set; }
}

然后将网格的数据源 属性 绑定到这样的行列表

this.gridRows = new List<GridRow>();
this.grid.DataSource = this.gridRows;

然后要添加新行,请执行此操作

this.gridRows.Add(new GridRow() { BS = "some value", Repare = "Some value", Quantity = 10});
this.gridView1.RefreshData();