Problems with Data Grid

ElPiponElPipon COMember ✭✭

Hello everyone, i am using the plugin of https://github.com/akgulebubekir/Xamarin.Forms.DataGrid

I press a button and fill the datagrid and open the page which contains two buttons and a search bar control in addition to the datagrid. When opening the page appears the datagrid with the data that I sent, the problem is that when pressing the buttons the list should be filled with other data, the same with the search bar. But instead the data grid is empty and does not show me anything.

How can I solve this problem?

My code is this:

XAML

<?xml version="1.0" encoding="utf-8" ?>
<OrientationContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Prueba4La14.Pages.ProductsPage"
             Title="Lista Productos"
             xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
             BackgroundColor="White"
             BindingContext="{Binding Main, Source={StaticResource Locator}}">
    <StackLayout Orientation="Vertical" Padding="0,10,0,10">
        <StackLayout Orientation="Horizontal" Padding="5,5,5,5">
            <Button
          Text="Chequeados"
          BackgroundColor="Red"
          TextColor="Black"
          BorderWidth="1"
          BorderColor="Black"
          Command="{Binding ChequeadoCommand}"
          HorizontalOptions="StartAndExpand"
          VerticalOptions="Start">

            </Button>
            <Button
              Text="No Chequeados"
              BackgroundColor="Blue"
              TextColor="Black"
              BorderWidth="1"
              BorderColor="Black"
              Command="{Binding NoChequeadoCommand}"
              HorizontalOptions="Fill"
              VerticalOptions="End">

            </Button>
        </StackLayout>
        <SearchBar    
            x:Name="searchbar"
            Placeholder="Buscar..."
            Text="{Binding Filter, Mode=TwoWay}"
            TextColor="Black"
            SearchCommand="{Binding SearchProductCommand}">
    </SearchBar>
        <dg:DataGrid Padding="0,10,0,0" ItemsSource="{Binding Productos}" SelectionEnabled="True" SelectedItem="{Binding SelectItemAsync}"
                         RowHeight="40" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8"  
                         ActiveRowColor="#8899AA">

            <dg:DataGrid.HeaderFontSize>
                <OnIdiom  x:TypeArguments="x:Double">
                    <OnIdiom.Tablet>15</OnIdiom.Tablet>
                    <OnIdiom.Phone>12</OnIdiom.Phone>
                </OnIdiom>
            </dg:DataGrid.HeaderFontSize>
            <dg:DataGrid.Columns >
                <dg:DataGridColumn x:Name="columncodigo" Title="Codigo" PropertyName="Codigo"/>
                <dg:DataGridColumn x:Name="columnean" Title="EAN" PropertyName="EAN"/>
                <dg:DataGridColumn x:Name="columndescripcion" Title="Descripcion" PropertyName="Descripcion" SortingEnabled="True"/>
                <dg:DataGridColumn x:Name="columnprecio" Title="Precio" PropertyName="Precio" SortingEnabled="True" />
            </dg:DataGrid.Columns>
            <dg:DataGrid.RowsBackgroundColorPalette>
                <dg:PaletteCollection>
                    <Color>#F2F2F2</Color>
                    <Color>#FFFFFF</Color>
                </dg:PaletteCollection>
            </dg:DataGrid.RowsBackgroundColorPalette>
        </dg:DataGrid>
    </StackLayout>

</OrientationContentPage>

And Function Search Products In Search Bar

 public void SearchProduct()
        {
            IsRunning2 = true;
            Task.Run(() =>
            {
                try
                {
                    var da = new DataAccess();
                    responsee = GetProductsdetalle(Filter);
                    responsee2 = GetProducts(Filter);

                    Productos.Clear();
                    Log.State("Buscar producto (listado)", 1);
                    foreach (var product2 in responsee2)
                    {
                        if (!responsee.Exists(p => p.Codigo == product2.Codigo))
                        {
                            Productos.Add(new ProductItemViewModel
                            {
                                IDListado = product2.IDListado,
                                Codigo = product2.Codigo,
                                EAN = product2.EAN,
                                Descripcion = product2.Descripcion,
                                Precio = "0"
                            });
                        }
                        else
                        {
                            Productos.Add(new ProductItemViewModel
                            {
                                IDListado = product2.IDListado,
                                Codigo = product2.Codigo,
                                EAN = product2.EAN,
                                Descripcion = product2.Descripcion,
                                Precio = Convert.ToString(responsee.FirstOrDefault(p =>p.Codigo == product2.Codigo).p_venta)
                            });
                        }
                    }
                    Log.State("Buscar producto (listado)", 2);

                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                }
            });
            IsRunning2 = false;
        }
Sign In or Register to comment.