简体   繁体   中英

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:

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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