踩坑日记 - DevExpress GridControl设置DataSource数据源无效
场景重现
一级明细表切换当前行自动显示二级表的明细记录,当修改二级明细表的资料后,再切换当前行,会发现录入的数据不见了。
解决方案
给GridControl数据源赋值后,必须调用RefreshDataSource方法刷新数据源!!!
C# 全选
private void gvCustomerCartons_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
var row = gvCustomerCartons.GetRow<dt_CustomerCartons>();
if (row != null)
{
gcMaterialsFormula.DataSource = _DetailData.ListCartons_MaterialsFormula.Where(w => w.CartonCode == row.CartonCode).ToList();
gcProcessSettings.DataSource = _DetailData.ListCartons_ProcessSettings.Where(w => w.CartonCode == row.CartonCode).ToList();
gcSpecConvert.DataSource = _DetailData.ListCartons_SpecConvert.Where(w => w.CartonCode == row.CartonCode).ToList();
gcWrapQtySettings.DataSource = _DetailData.ListCartons_WrapQtySettings.Where(w => w.CartonCode == row.CartonCode).ToList();
}
else
{
gcMaterialsFormula.DataSource = new List<dt_CustomerCartons_MaterialsFormula>();
gcProcessSettings.DataSource = new List<dt_CustomerCartons_ProcessSettings>();
gcSpecConvert.DataSource = new List<dt_CustomerCartons_SpecConvert>();
gcWrapQtySettings.DataSource = new List<dt_CustomerCartons_WrapQtySettings>();
}
//必须调用RefreshDataSource方法刷新数据源!!!
gcMaterialsFormula.RefreshDataSource();
gcProcessSettings.RefreshDataSource();
gcSpecConvert.RefreshDataSource();
gcWrapQtySettings.RefreshDataSource();
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网