![](/img/trans.png)
[英]How to add new line of row in devexpress gridcontrol?(WinForms C#)
[英]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 GridRow
{
public string BS { get; set;}
public string Repere { get; set; }
public string Profil { get; set; }
public int Quantity { get; set; }
}
然后將網格的DataSource屬性綁定到這樣的行列表
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.