Implementing IDataSourceSelector error-Solved

Hi i have a error,


I initialize the sfdatagrid

private void IniciarGridPartidas()
        {
            DgFases.Columns.Clear();
            DgFases.Columns.Add(
            new GridNumericColumn()
            {
                MappingName = "Porcentaje",
                HeaderText = "%",
                ValidationMode = Syncfusion.WinForms.DataGrid.Enums.GridValidationMode.InEdit,
                FormatMode = FormatMode.Percent,
                AllowEditing = false
            });

            DgFases.Columns.Add(new GridComboBoxColumn()
            {
                MappingName = "FIDactuacion",
                HeaderText = "Actuacion",
                ValueMember = "IdActuacion",
                DisplayMember = "Actuacion",
                DropDownStyle = DropDownStyle.DropDownList,
                DataSource = Actuaciones,
            });

            DgFases.Columns.Add(new GridComboBoxColumn()
            {
                MappingName = "FIDfase",
                HeaderText = "Fase",
                AllowNull = true,
                ValueMember = "IDfase",
                DisplayMember = "fase",
                DropDownStyle = DropDownStyle.DropDownList,
                IDataSourceSelector = new SeleccionaFases()
            });

            //sfDataGrid1.Columns.Add(new GridComboBoxColumn()
            //{
            //   // MappingName = "IdPartida",
            //    HeaderText = "Partida",
            //    ValueMember = "IdPartida",
            //    DisplayMember = "Partida",
            //    DropDownStyle = DropDownStyle.DropDown,
            //    //IDataSourceSelector = new CustomSelectorPartidas2()//DataSource = partidas,
            //});

            //sfDataGrid1.Columns.Add(new GridComboBoxColumn()
            //{
            //    MappingName = "IdConcepto",
            //    HeaderText = "Concepto",
            //    //ValueMember = "IdConcepto",
            //    //DisplayMember = "Concepto",
            //    //DropDownStyle = DropDownStyle.DropDown,
            //    //IDataSourceSelector = new CustomSelectorConcepto2()//DataSource = conceptos,
            //});

            NumberFormatInfo numberFormat = Application.CurrentCulture.NumberFormat.Clone() as NumberFormatInfo;
            numberFormat.NumberDecimalDigits = 2;
            numberFormat.NumberDecimalSeparator = ",";
            numberFormat.CurrencySymbol = "€";
            numberFormat.NumberGroupSizes = Array.Empty<int>();

            DgFases.Columns.Add(
            new GridNumericColumn()
            {
                MappingName = "Importe",
                HeaderText = "Importe",
                ValidationMode = Syncfusion.WinForms.DataGrid.Enums.GridValidationMode.InEdit,
                FormatMode = FormatMode.Currency,
                NumberFormatInfo = numberFormat,
                AllowEditing = false
            });

            DgFases.ShowRowHeader = true;
            DgFases.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.AllCellsWithLastColumnFill;
        }

The selector

public class SeleccionaFases : IDataSourceSelector
    {
        public IEnumerable GetDataSource(object record, object dataSource)
        {
            try
            {
                if (record == null)
                    return null;

                CONTRATOS_ACTUACIONES infoActuaciones = record as CONTRATOS_ACTUACIONES;
                int idactuacion = infoActuaciones.FIDactuacion;
                using (XesturEntities datos = new XesturEntities())
                {
                    var q =  (from f in datos.FASES
                             where f.FIDactuacion == idactuacion
                             select f).ToList();

                    if (q != null)
                        return new ObservableCollection<FASES>(q);
                    else
                        return null;
                }
            }
            catch (Exception ex)
            {
                return null;

            }
        }


    }


I need insert a row and the user select the correct value

 foreach (ActuacionRedMultiColumn actuacion in Actuaciones)
            {
                lista.Add(new CONTRATOS_ACTUACIONES
                {
                    //Actuacion = actuacion.Actuacion,
                    FIDactuacion = actuacion.IdActuacion,
                    Porcentaje = Expe_Actuaciones.Where(ex => ex.IdActuacion == actuacion.IdActuacion && ex.IdLote == Lote.Id).Select(s => s.Porcentaje).FirstOrDefault(),
                    Importe = Expe_Actuaciones.Where(ex => ex.IdActuacion == actuacion.IdActuacion && ex.IdLote == Lote.Id).Select(s => s.Importe).FirstOrDefault(),
                    FIDexpediente = Expediente.IdExpediente
                });
            }
            
            DgFases.DataSource = lista;


The program have a excepcion, if i comment out IDataSourceSelector = new SeleccionaFases() works fine. null reference exception

Thanks


5 Replies

SS Susmitha Sundar Syncfusion Team May 5, 2020 11:42 AM UTC

Hi Ruben, 

Thank you for using Syncfusion controls. 

We have prepared the sample based on your requirement “IDataSourceSelector”. Its works fine from our end. We did not get any exception from IDataSouceSelector. 
  
  
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us back with the following details,  
  
·             Issue reproducing procedure (Please confirm whether issue occurs at loading time or at adding the new item). 
·             Syncfusion update version  
·             Share the stack trace for this issue. 
 
It will be helpful for us to check on it and provide you the solution at the earliest.    
  
Regards,  
Susmitha S  
 



RU Ruben May 5, 2020 02:08 PM UTC

Hi, thanks for the reply


Issue reproducing procedure-> When add a new item

Syncfusion update version  ->18.1460.0.45

Share the stack trace for this issue -> 
   en Syncfusion.WinForms.DataGrid.GridComboBoxColumn.GetFormattedValue(Object record, Object value)
   en Syncfusion.WinForms.DataGrid.Data.DataGridItemsPropertiesProvider.GetFormattedValue(Object record, String propName, Object& value)
   en Syncfusion.WinForms.DataGrid.Data.DataGridItemsPropertiesProvider.GetFormattedValue(Object record, String propName)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.GetDisplayText(GridColumn column, Object record)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.GetColumnAutoSizeWidth(GridColumn column)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.CalculateAllCellsExceptHeaderWidth(GridColumn column, Boolean setWidth)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.CalculateAllCellsWidth(GridColumn column, Boolean isAllCells)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.GetColumnSizerWidth(GridColumn column, AutoSizeColumnsMode autoSizeColumnsMode)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.SetColumnWidthsBasedOnGrid(Double totalColumnSize, List`1 calculatedColumns, Double viewPortWidth)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.SetColumnSizerWidths(Double viewPortWidth)
   en Syncfusion.WinForms.DataGrid.AutoSizeController.Refresh()
   en Syncfusion.WinForms.DataGrid.AutoSizeController.OnRowHeightsLineHiddenChanged(Object sender, HiddenRangeChangedEventArgs e)
   en Syncfusion.WinForms.GridCommon.ScrollAxis.HiddenRangeChangedEventHandler.Invoke(Object sender, HiddenRangeChangedEventArgs e)
   en Syncfusion.WinForms.GridCommon.ScrollAxis.LineSizeCollection.ResumeUpdates()
   en Syncfusion.WinForms.DataGrid.TableControl.UpdateRowCount()
   en Syncfusion.WinForms.DataGrid.TableControl.UpdateRowAndColumnCount(Boolean canGenerateVisibleColumns, Boolean canUpdateRowCount)
   en Syncfusion.WinForms.DataGrid.SfDataGrid.SetSourceList(Object itemsSource, DataSourceChangedEventArgs args)
   en Syncfusion.WinForms.DataGrid.SfDataGrid.RefreshViewAndContainer(Object oldValue, Object newValue)
   en Syncfusion.WinForms.DataGrid.SfDataGrid.<>c__DisplayClass79.<OnDataSourceChanged>b__78()
   en Syncfusion.WinForms.DataGrid.BusyIndicatorHelper.RunWork(SfDataGrid dataGrid, Action work, BusyIndicatorAction busyIndicatorAction, Boolean showBusyIndicator)
   en Syncfusion.WinForms.DataGrid.SfDataGrid.OnDataSourceChanged(Object oldValue, Object newValue)
   en Syncfusion.WinForms.DataGrid.SfDataGrid.set_DataSource(Object value)
   en Xesta.Formularios.FormExpedienteaContrato.CargarDatosPartidas() en C:\ProyectoXestur\Xesta\Xesta\Formularios\FormExpedienteaContrato.cs: línea 74
   en Xesta.Formularios.FormExpedienteaContrato.FormExpedienteaContrato_Load(Object sender, EventArgs e) en C:\ProyectoXestur\Xesta\Xesta\Formularios\FormExpedienteaContrato.cs: línea 233
   en System.Windows.Forms.Form.OnLoad(EventArgs e)
   en Syncfusion.Windows.Forms.MetroForm.OnLoad(EventArgs e)
   en System.Windows.Forms.Form.OnCreateControl()
   en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   en System.Windows.Forms.Control.CreateControl()
   en System.Windows.Forms.Control.WmShowWindow(Message& m)
   en System.Windows.Forms.Control.WndProc(Message& m)
   en System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   en System.Windows.Forms.Form.WmShowWindow(Message& m)
   en System.Windows.Forms.Form.WndProc(Message& m)
   en Syncfusion.Windows.Forms.MetroForm.WndProc(Message& m)
   en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


The excepcion at this moment
 foreach (ActuacionRedMultiColumn actuacion in Actuaciones)
            {
                decimal porcentaje = Expe_Actuaciones.Where(ex => ex.IdActuacion == actuacion.IdActuacion && ex.IdLote == Lote.Id).Select(s => s.Porcentaje).FirstOrDefault();
                
                lista.Add(new CONTRATOS_ACTUACIONES
                {
                    FIDactuacion = actuacion.IdActuacion,
                    Porcentaje = porcentaje,
                    Importe = Oferta.Importe * (porcentaje /100),
                    FIDexpediente = Expediente.IdExpediente
                });
            }
            
            DgFases.DataSource = lista;

Thanks


SS Susmitha Sundar Syncfusion Team May 6, 2020 03:27 PM UTC

Hi Ruben,  

Thank you for the update.  

We have checked your reported case with IDataSourceSelector.  But unfortunately, we did not get any exception while adding the new item. Please refer our sample,  
   
   
Please check the sample and let us know if you still facing the same issue?If not, please modify the sample based on your scenario.  
  
It will be helpful for us to check on it and provide you the solution at the earliest.     
   
Regards,   
Susmitha S   





RU Ruben replied to Susmitha Sundar May 6, 2020 04:42 PM UTC

Hi Ruben,  

Thank you for the update.  

We have checked your reported case with IDataSourceSelector.  But unfortunately, we did not get any exception while adding the new item. Please refer our sample,  
   
   
Please check the sample and let us know if you still facing the same issue?If not, please modify the sample based on your scenario.  
  
It will be helpful for us to check on it and provide you the solution at the earliest.     
   
Regards,   
Susmitha S   




Hi, i found the problem

 In my static class implement the INotifyPropertyChanged and works fine.

public partial class CA : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;

            private void RaisePropertyChanged(string name)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
            public int FIDcontrato { get; set; }
            public int FIDactuacion { get; set; }
            public decimal Porcentaje { get; set; }
            public decimal Importe { get; set; }
            public int FIDfase { get; set; }
            public int FIDexpediente { get; set; }
        }


SS Susmitha Sundar Syncfusion Team May 7, 2020 05:37 AM UTC

Hi Ruben, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Susmitha S 


Loader.
Up arrow icon