Xamarin.Forms.Datagird How to expand the data grid when a another value to the collection?

Fourie Laing 1 Reputation point
2022-02-09T06:29:13.893+00:00

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.

172385-screenshot-2022-02-09-082424.png

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

172370-screenshot-2022-02-09-082633.png

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

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,206 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Fourie Laing 1 Reputation point
    2022-02-09T14:37:10.543+00:00

    I needed to increase the Height of the control. Was such a simple thing

                    <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 Height>