Details view problem

Hi, 

 I have a problem when populate the list of detailsviewdatasource, if add a item outside the form the control only shows the items loaded in first time, the list have the correct elements if close the form and loaded works fine.

private void SfDataGrid_DetailsViewExpanding(object sender, DetailsViewExpandingEventArgs e)
        {
            ExpedientesContratacionLotes exp = e.Record as ExpedientesContratacionLotes;
            if (exp.Id > 0)
            {
                using (Entities datos = new Entities())
                {
                    List<CodigosCPV> lista = new List<CodigosCPV>();
                    
                    lista = (from c in datos.ExpedientesContratacionLotesCPV
                                               join cp in datos.CodigosCPV
                                               on c.IdCPV equals cp.IdCodigo
                                               where c.IdLote == exp.Id
                                               select cp
                                                ).ToList();
                    e.DetailsViewDataSource.Add("CodigosCPV", lista);
                    if (lista.Count() > 0)
                    {
                        //e.DetailsViewDataSource.Add("CodigosCPV", lista);
                        //DgLotes.Refresh();
                    }
                }
            }
        }

The grid constructor

DgLotes.DataSource = lista_exp_lotes;
            DgLotes.Columns.Clear();
            DgLotes.EditorSelectionBehavior = EditorSelectionBehavior.SelectAll;
            DgLotes.Columns.Add(
            new GridNumericColumn()
            {
                MappingName = "Numero",
                HeaderText = "Nº",
                ValidationMode = GridValidationMode.InEdit,
                NumberFormatInfo = new NumberFormatInfo() { NumberDecimalDigits = 0 },
                FormatMode = FormatMode.Numeric,
                MaximumWidth = 50
            });
            DgLotes.Columns.Add(
            new GridTextColumn()
            {
                MappingName = "Nombre",
                HeaderText = "Nombre",
                ValidationMode = GridValidationMode.InEdit,
            });
            DgLotes.Columns.Add(
                new GridTextColumn()
                {
                    MappingName = "Descripcion",
                    HeaderText = "Descripcion",
                    ValidationMode = GridValidationMode.InEdit
                });

            DgLotes.Columns.Add(
               new GridNumericColumn()
               {
                   MappingName = "Importe",
                   HeaderText = "Importe",
                   ValidationMode = GridValidationMode.InEdit,
                   MaximumWidth = 120,
                   NumberFormatInfo = numberFormat
               });

            DgLotes.CellRenderers.Remove("ComboBox");
            DgLotes.CellRenderers.Add("ComboBox", new GridComboBoxCellRendererExt());
            DgLotes.Columns.Add(new GridButtonColumn()
            {
                HeaderText = "+",
                MappingName = "UnboundColumn",
                AllowFiltering = false,
                AllowDefaultButtonText = true,
                DefaultButtonText = "",
                ImageSize = new Size(16, 16),
                AutoSizeColumnsMode = AutoSizeColumnsMode.AllCells,
                Image = Resources.add_161,
                MaximumWidth = 30,
                CellStyle = new CellStyleInfo { HorizontalAlignment = HorizontalAlignment.Center },
            });

            DgLotes.Columns.Add(new GridButtonColumn()
            {
                HeaderText = "X",
                MappingName = "UnboundColumn",
                AllowFiltering = false,
                AllowDefaultButtonText = true,
                DefaultButtonText = "",
                ImageSize = new Size(16, 16),
                AutoSizeColumnsMode = AutoSizeColumnsMode.AllCells,
                Image = Resources.feEliminar_16,
                MaximumWidth = 30,
                CellStyle = new CellStyleInfo { HorizontalAlignment = HorizontalAlignment.Center },
            });
            GridViewDefinition firstLevelGridViewDefinition = new GridViewDefinition
            {
                RelationalColumn = "CodigosCPV"
                
            };
            firstLevelGridViewDefinition.DataGrid.Style.HeaderStyle.BackColor = ColorTranslator.FromHtml("#CAECCF");
            SfDataGrid firstLevelNestedGrid = new SfDataGrid
            {
                AllowSorting = true,
                AllowFiltering = true,
                AllowResizingColumns = true,
                AutoGenerateColumns = false,
                AutoSizeColumnsMode = AutoSizeColumnsMode.AllCellsWithLastColumnFill

            };
            firstLevelNestedGrid.Columns.Add(new GridTextColumn() { MappingName = "Codigo", HeaderText = "Codigo",Width = 90 });
            firstLevelNestedGrid.Columns.Add(new GridTextColumn() { MappingName = "Descripcion", HeaderText = "Descripcion",Width = 350 });

            firstLevelGridViewDefinition.DataGrid = firstLevelNestedGrid;

            DgLotes.DetailsViewDefinitions.Add(firstLevelGridViewDefinition);
            DgLotes.DetailsViewExpanding += SfDataGrid_DetailsViewExpanding;


Thanks


3 Replies

MA Mohanram Anbukkarasu Syncfusion Team September 2, 2020 02:04 PM UTC

Hi Ruben, 

Thanks for contacting Syncfusion support.  

We are little unclear with your update. We suspect that the issue you are facing is the item added to the underlying collection at runtime is not reflected to the SfDataGrid. From the provided code snippet we suspect that you are using List type collection as the data source. We Suggest you to make use of ObservableCollection which implements INotifyCollectionChanged interface by default. So that the changes like add, remove or clear action made to the collection will be automatically reflected to the DataGrid as per your expectation.  

Please revert to us with more details about the problem you are facing with a sample application and a video illustration, if we have misunderstood your update. It will be more helpful for us to provide a prompt solution at earlier.  

Regards, 
Mohanram A. 



RU Ruben September 2, 2020 03:09 PM UTC

Thanks, I implement it and tell you the result



VS Vijayarasan Sivanandham Syncfusion Team September 3, 2020 05:56 AM UTC

Hi Ruben,

Thanks for the update.
 
 
We will wait to hear from you. 
 
Regards, 
Vijayarasan S 


Loader.
Up arrow icon