解决DevExpress GridControl 用List无法在列表上添加新行问题

来源:互联网 发布:怕错过了也不会知 编辑:程序博客网 时间:2024/05/29 12:32

症状描述:

GridControl .DataSource绑定一个List时,可以显示,但无法在列表上添加新行
表现为能出现新行编辑,但移开焦点后,输入的值就消失了

protected override void OnLoad(EventArgs e){    base.OnLoad(e);    this.gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;    _source = new BindingList<CargoInfo>();    _source.Add(new CargoInfo() { VoyageNo = "aaa", LoadTime = DateTime.Now, PortCode = "1234" });    _source.Add(new CargoInfo() { VoyageNo = "aaa", LoadTime = DateTime.Now, PortCode = "4321" });    gridControl1.DataSource = _source;}public class CargoInfo{    public string VoyageNo {get;set;}    public string PortCode { get; set; }    public DateTime? LoadTime { get; set; }}

再仔细阅读文档,发现GridControl 支持编辑需要使用 BindingList列表。更换后测试果然可以了

解决方案:

_source = new BindingList<CargoInfo>();
0 0
原创粉丝点击