BindingList 未使用 gridview 实时更新

问题描述 投票:0回答:1

我创建了一个自定义类并实现了它的接口 INotifyPropertyChanged 和 INotifyPropertyChanging,我将数据源分配给了网格视图,但它没有按照我的预期在屏幕上更新。如果我向列表中添加一个元素,它会实时显示,但如果我修改一个值并在单元格值更改事件中分配一些操作,则不会实时显示

我附上部分课程


 public class PrecioServiciosSegurosModelo : INotifyPropertyChanged, INotifyPropertyChanging
 {
     private int _id;
     private int _coberturaID;
     private int _servicioID;
     private int _seguroID;
     private decimal _preBase;
     private decimal _precioFinal;
     private decimal _montoSeguro;
     private decimal _adicional;
     private int _nuevo;
     private DB.Coberturas _coberturas;
     private DB.Seguros _seguros;
     private DB.Servicios _servicios;

     public int ID
     {
         get { return _id; }
         set { SetProperty(ref _id, value); }
     }

     public int CoberturaID
     {
         get { return _coberturaID; }
         set { SetProperty(ref _coberturaID, value); }
     }

     public int ServicioID
     {
         get { return _servicioID; }
         set { SetProperty(ref _servicioID, value); }
     }

     public int SeguroID
     {
         get { return _seguroID; }
         set { SetProperty(ref _seguroID, value); }
     }

     public decimal PreBase
     {
         get { return _preBase; }
         set { SetProperty(ref _preBase, value); }
     }

     public decimal PrecioFinal
     {
         get { return _precioFinal; }
         set { SetProperty(ref _precioFinal, value); }
     }

     public decimal MontoSeguro
     {
         get { return _montoSeguro; }
         set { SetProperty(ref _montoSeguro, value); }
     }

     public decimal Adicional
     {
         get { return _adicional; }
         set { SetProperty(ref _adicional, value); }
     }
 public event PropertyChangedEventHandler PropertyChanged;

 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
 {
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
 }

 public event PropertyChangingEventHandler PropertyChanging;

 protected virtual void OnPropertyChanging([CallerMemberName] string propertyName = null)
 {
     PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName));
 }

 private bool SetProperty<T>(ref T backingField, T value, [CallerMemberName] string propertyName = null)
 {
     if (EqualityComparer<T>.Default.Equals(backingField, value))
     {
         return false;
     }

     OnPropertyChanging(propertyName);
     backingField = value;
     OnPropertyChanged(propertyName);
     return true;
 }

这是我的列表,我将其从 icollection 转换为绑定列表

 public class preseguroservicios
 {
     public static BindingList<PrecioServiciosSegurosModelo> Items = new BindingList<PrecioServiciosSegurosModelo>();

    

     public static void ToBindinglist(ServicioModelo objeto)
     {
         Items = new BindingList<PrecioServiciosSegurosModelo>(objeto.precioServicioSeguro.ToList());
     }
 public static void EditMontos(int Row)
 {
      
     //Items[Row].PrecioFinal = Items[Row].Pre_Base - (Items[Row].Pre_Base * Items[Row].Coberturas.PorcentajeCobertura / 100) + Items[Row].Adicional;
     Items[Row].MontoSeguro = (Items[Row].PreBase * Items[Row].Coberturas.PorcentajeCobertura / 100);
     //  Items[Row].PrecioFinal = Cant * Presentaciones[Row].Precio_Unidad;

 } 

在网格视图的单元格值更改事件中,我有以下内容

`

 private void viewcoberturas_CellValueChanging_1(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
 {
   
    
         preseguroservicios.EditMontos(e.RowHandle);


 }

`
c# .net winforms devexpress
1个回答
0
投票

我有一种感觉,使用 CellValueChanging 事件以这种方式修改值是错误的,但是调用 GridControl 的 RefreshDataSource 方法应该可以解决这个问题。

注意这是一个 GridControl 方法,而不是 GridView/BaseView 方法。

© www.soinside.com 2019 - 2024. All rights reserved.