【问题标题】:How to add new row to unbound devexpress GridControl?如何向未绑定的 devexpress GridControl 添加新行?
【发布时间】:2018-12-21 19:29:30
【问题描述】:

我已经创建了网格控件并在设计器中添加了 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);

但是当我运行代码时没有发生任何事情,我的网格控件没有绑定到任何类型的数据,我该如何解决这个问题? , 先谢谢了。

【问题讨论】:

    标签: c# winforms devexpress


    【解决方案1】:

    声明一个将保存单行数据的类

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

    【讨论】:

    • 感谢您的帮助,我非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    相关资源
    最近更新 更多