简体   繁体   English

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

[英]How to add new row to unbound devexpress GridControl?

I have create grid controle and in designer I add 4 columns(BS, Repere, Profil, Quantity),and I want to add new row in click of button, so I use this code: 我创建了网格控件,并在设计器中添加了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);

but when I run the code nothing happend,my grid control not binding to any type of data ,How do I solve this problem? 但是,当我运行代码时,什么都没发生,我的网格控件未绑定到任何类型的数据,如何解决此问题? , Thanks in advance. , 提前致谢。

Declare a class that will hold the data for a single Row 声明一个类,该类将保存单个行的数据

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

then bind the grid's DataSource property to a list of rows like this 然后将网格的DataSource属性绑定到这样的行列表

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

then to add a new row do this 然后添加新行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM