Error while set itemssource to sfDataGrid

I have a sdFataGrid and the first time when I set a itemsource the grid shows fine, but when I get the source list from the grid and update or add an object to the list and set the list again to the grid the app throws "An unhandled exception occured"

The data is update or adding by a method executed by a clic event

XAML CODE:

<RelativeLayout>
            <ScrollView x:Name="scroll" Orientation="Vertical"
                    HorizontalOptions="Fill"
                    VerticalOptions="Fill"
                        RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=0}"
                        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}">
                <StackLayout x:Name="stackLayout" Orientation="Vertical" Spacing="15" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
                           RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=0}"
                        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}">
                    <syncfusion:SfDataGrid x:Name="DataGrid" ColumnSizer="Star" AutoGenerateColumns="False"
                                           VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                        <syncfusion:SfDataGrid.Columns x:TypeArguments="syncfusion:Columns">
                            <syncfusion:GridTextColumn HeaderText="ActivoId" MappingName="ActivoId" IsHidden="True" />
                            <syncfusion:GridTextColumn HeaderText="Co. barras" MappingName="CodigoBarrasParticular" />
                            <syncfusion:GridTextColumn HeaderText="Estatus" MappingName="NombreEstatus" />
                            <syncfusion:GridImageColumn HeaderText="Validacion" MappingName="EstatusIdSource" />
                            <syncfusion:GridTextColumn HeaderText="Estatus Id" MappingName="EstatusId" IsHidden="True" />
                        </syncfusion:SfDataGrid.Columns>
                    </syncfusion:SfDataGrid>
                </StackLayout>
            </ScrollView>
        </RelativeLayout>

C# CODE:

 public async void VerificarActivo(string scannCodigoBarras)
        {
            MostrarLoad();

            //Se obtienen las entidades del DataGrid
            var Repositorio = new ActivosAsignadosEntidadRepositorio
            {
                ColeccionActivosAsignados = (DataGrid.ItemsSource as List<ActivosAsignadosEntidad>).ToList()
            };

            //Se busca el codigo de barras en el grid
            foreach (var item in Repositorio.ColeccionActivosAsignados)
            {
                if (item.CodigoBarrasParticular.Equals(scannCodigoBarras))
                {
                    string mensajePopUp;

                    if (item.EstatusId == 25)
                    {
                        item.EstatusId = 24;
                        item.NombreEstatus = "Localizado";
                        item.EstatusIdSource = ImageSource.FromFile("s24.png");      
                        //Here the app throws an error
                        DataGrid.ItemsSource = Repositorio.ColeccionActivosAsignados;
                        EntryCodigoBarras.Text = string.Empty;
                        CodigoBarras = string.Empty;
                        mensajePopUp = Constantes.ActivoMensaePopUpCorrecto;
                    }
                    else
                        mensajePopUp = Constantes.ActivoMensaePopUpYaEscaneado;

                    OcultarLoad();
                    ShowPopUp(mensajePopUp);
                    return;
                }
            }
}

ENTITY CODE: 

    public class ActivosAsignadosEntidad
    {
        private int activoId;
        private string codigoBarrasParticular;
        private string nombreEstatus;
        private ImageSource estatusIdSource;
        private int estatusId;

        public int ActivoId { get => activoId; set => activoId = value; }
        public string CodigoBarrasParticular { get => codigoBarrasParticular; set => codigoBarrasParticular = value; }
        public string NombreEstatus { get => nombreEstatus; set => nombreEstatus = value; }
        public ImageSource EstatusIdSource { get => estatusIdSource; set => estatusIdSource = value; }
        public int EstatusId { get => estatusId; set => estatusId = value; }

        public ActivosAsignadosEntidad(int activoId, string codigoBarrasParticular, string nombreEstatus, int estatusId)
        {
            this.activoId = activoId;
            this.codigoBarrasParticular = codigoBarrasParticular;
            this.nombreEstatus = nombreEstatus;
            this.estatusIdSource = ImageSource.FromFile("s" + estatusId + ".png");
            this.estatusId = estatusId;
        }
    }

VIEWMODEL CODE:

    public class ActivosAsignadosEntidadRepositorio
    {
        private List<ActivosAsignadosEntidad> coleccionActivosAsignados;

        public List<ActivosAsignadosEntidad> ColeccionActivosAsignados { get => coleccionActivosAsignados; set => coleccionActivosAsignados = value; }
    }

1 Reply

VP Vimal Prabhu Manohkaran Syncfusion Team October 18, 2017 09:47 PM UTC

Hi Abraham,

Thanks for using Syncfusion products. We have checked with your query and have prepared a sample with the codes that you have given below. In the sample we have loaded your data and are refreshing the itemsource in the runtime via a button click. Unfortunately we are not able to reproduce the issue even after numerous clicks on the button and data refreshing happens fine. Also the code that you have given with the title C# makes calls to different methods like MostrarLoad(), OcultarLoad(); etc whose codes were not shared with us
. Hence we are pretty sure that the unhandled exception is not from the SfDataGrid and might be due to the operations you perform in one of these functions. So kindly request you to check the same.

However if you are performing any SfDataGrid related operations inside the methods whose code you have not shared with us, kindly request you to share your complete issue replicating sample, or modify our sample from the below link to replicate the issue and provide the codes of that methods as well.

Sample Link : http://www.syncfusion.com/downloads/support/forum/133256/ze/Forms-739556947

Regards,
Vimal Prabhu 


Loader.
Up arrow icon