Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
350
XamGrid Summary ColumnLayout
posted

Hi,

I have some problem to refresh value on column who depend of child item.

My model is define in the sample.

I would like to have the Sum of Qty delivery for each items

I tried something like this :

<ig:XamGrid x:Name="ControleGrid"

                    Width="auto"               

                    ItemsSource="{Binding Items}" 

                    AutoGenerateColumns="False"

                    IsAlternateRowsEnabled="False">

           

            <ig:XamGrid.Columns>

<ig:TextColumn Key="DeliveryQuantityQty" ></ig:TextColumn>

 

<ig:ColumnLayout Key="Deliveries">

  <ig:ColumnLayout.AddNewRowSettings>

<ig:AddNewRowSettingsOverride AllowAddNewRow="Bottom"/>

</ig:ColumnLayout.AddNewRowSettings>

                            <ig:ColumnLayout.Columns>

                                <ig:TextColumn Key="Qty" ></ig:TextColumn>

                            </ig:ColumnLayout.Columns>

</ig:ColumnLayout>

            </ig:XamGrid.Columns>

        </ig:XamGrid>

Problem : When i add row in the Delivries in the ColumnLayout the parent column DeliveryQuantityQty is not update.

When i use sort function of XamGrid on column the DeliveryQuantityQty is update.

I would like to get the new value after adding Delivery.

Is there any way to avoid this problem ? (use summary function in header of columnlayout is a possibility ?)

Thanks a lot for your help.

XamGrid_sample_Refresh.zip
Parents
No Data
Reply
  • 6365
    Offline posted

    Hello,

    Thank you for the sample application you have provided.

    The reason the "Qty" column from the top layout is updated only when performing operations like sorting is because the XamGrid gets all property values when sorting and in this case the QtyDelivered property returns the latest calculation result.

    In order to keep the QtyDelivered property updated when adding new child rows, I can suggest you a couple of approaches:

    1. Handle the RowAdded event of the XamGrid by checking if a new row has been added to the child layout. If so, then update the QtyDelivered property of the parent row manually.


    private void grid_RowAdded(object sender, RowEventArgs e)
    {
        var grid = sender as XamGrid;
        var addedRow = e.Row;

        if (addedRow.ColumnLayout == grid.ColumnLayouts["Deliveries"])
        {
            var parentRow = addedRow.ParentRow;
            var parentRowItem = (parentRow.Data as Item);
            parentRowItem.QtyDelivered = parentRowItem.Deliveries.Sum(D => D.Qty);
        }
    }

    2. Use an ObservableCollection instead of a List for storing the Delivery items. This way you can hook for the CollectionChanged event of the collection and update the QtyDelivered property with a private set within the Item class context.


    this._Deliveries = new ObservableCollection<Delivery>();
    this._Deliveries.CollectionChanged += (sender, e) =>
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            QtyDelivered = this.Deliveries.Sum(D => D.Qty);
        }
    };

    I would suggest going with the second approach, since it keeps the MVVM pattern and the ObservableCollection itself is more suitable when it comes to storing data for visual representation.
    I have modified your sample with the second approach from above.

    If you have any questions on the matter, please let me know.

    XamGrid_sample_Refresh(Modified).zip
Children