Home > Blockchain >  I'm trying to expand the Datagrid when adding another value. Using Xamarin.Forms.Datagrid
I'm trying to expand the Datagrid when adding another value. Using Xamarin.Forms.Datagrid

Time:02-14

I'm using Xamarin.Forms.Datagrid. What I'm struggling with is displaying the second row. I suspect it is in the adding value part that I'm not specifying to add a new row to the Datagrid. But for the life of me I can't see it.

Scanned First Entry

Now if I scanned a different barcode. It adds the new value to the collection but does not expand the datagrid.

Scanned Second Entry

My ObservableCollection:

public ObservableCollection<dgvProductionReceiptSource> ProductionReceiptSource { get; } = new ObservableCollection<dgvProductionReceiptSource>();

Where I get my data from:

private void FillDataGrid()
    {
        try
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand("SELECT DocNum, OWOR.ItemCode, ItemName, PlannedQty, CAST(OWOR.DueDate AS DATE) FROM OWOR "  
                    "INNER JOIN OITM ON OWOR.ItemCode = OITM.ItemCode WHERE Status = 'R' AND OWOR.DocNum = '"   ScanBarcodeText   "' ORDER BY DueDate ASC", connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {

                        if (reader != null)
                        {
                            while (reader.Read())
                            {
                                
                                ItemNum = reader.GetString(1);
                                Desc = reader.GetString(2);
                                PlannedQty = reader.GetDecimal(3);
                                DueDate = reader.GetDateTime(4);
                                ScanQty = 0;

                                if (DueDate == DateTime.Today)
                                {
                                    if (DocNum.ToString() == ScanBarcodeText)
                                    {
                                        AddQty();
                                    }
                                    
                                    if (DocNum.ToString() != ScanBarcodeText)
                                    {
                                        DocNum = reader.GetInt32(0);
                                        ProductionReceiptSource.Add(new dgvProductionReceiptSource()
                                        {
                                            DocNumProductionReceipt = DocNum,
                                            ItemNumberProductionReceipt = reader.GetString(1),
                                            DescriptionProductionReceipt = reader.GetString(2),
                                            PlannedQuantityProductionReceipt = reader.GetDecimal(3),
                                            ScannedQuantityProductionReceipt = 0
                                        });
                                        AddQty();
                                    }
                                }
                            }
                        }
                    }
                }
                connection.Close();
            }
            ScanBarcodeText = string.Empty;
        }
        catch(Exception ex)
        {
            Application.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
        }
    }

Any help would be appreciated

CodePudding user response:

Like Jason suggested, I need to increase the height of the control

            <ContentView HeightRequest="380">
                <ScrollView Orientation="Horizontal">
                    <dg:DataGrid x:Name="dgvProductionReceiptSource" 
                                 ItemsSource="{Binding ProductionReceiptSource}"
                                 IsRefreshing="{Binding ProductionReceiptRefresh}"
                                 PullToRefreshCommand="{Binding ProductionReceiptRefreshCommand}"
                                 IsVisible="False"
                                 RowHeight="60" 
                                 HeaderHeight="50"
                                 HeaderBackground="#e0e6f8"
                                 HeaderFontSize="15"
                                 ActiveRowColor="#8899AA">
                        <x:Arguments>
                            <ListViewCachingStrategy>RetainElement</ListViewCachingStrategy>
                        </x:Arguments>
                        <dg:DataGrid.Columns>
                            <dg:DataGridColumn Title="Order Number" PropertyName="DocNumProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Item Number" PropertyName="ItemNumberProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Item Description" PropertyName="DescriptionProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Planned Quantity" PropertyName="PlannedQuantityProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Scanned Bin" PropertyName="ScannedBinsProductionReceipt" Width="150"
                                               HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Remaining Bins" PropertyName="RemainingBinsProductionReceipt" Width="150"
                                               HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                        </dg:DataGrid.Columns>
                        <dg:DataGrid.RowsBackgroundColorPalette>
                            <dg:PaletteCollection>
                                <Color>#E0E6f8</Color>
                            </dg:PaletteCollection>
                        </dg:DataGrid.RowsBackgroundColorPalette>
                    </dg:DataGrid>
                </ScrollView>
            </ContentView>

I changed the ContentView HeightRequest

  • Related