BindingList not updating in real time with gridview

44 Views Asked by At

I created a custom class and implemented its interfaces INotifyPropertyChanged and INotifyPropertyChanging, I assigned the datasource to the grid view, but it is not updated on the screen as I expect. If I add an element to the list, it is displayed in real time, but if I modify a value and in the cellvaluechanging event I assign some action, this is not displayed in real time

I attach part of my class


 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;
 }

This is my list, which I convert from icollection to bindinglist

 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;

 } 

In the cellvaluechanging event of the gridview I have the following

`

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


 }

`
1

There are 1 best solutions below

0
Brendon On

I have a feeling that using the CellValueChanging event is the wrong place to be modifying values in this manner, but invoking the GridControl's RefreshDataSource method should resolve this.

Note this is a GridControl method, NOT a GridView/BaseView method.