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.
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); }}
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.
I have some question about second approach :
My items are retrieve by relationship from object generated by EDMX diagram :
public EntityCollection Livraisons //as deliveries { get { return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection("EasiiDB_001Model.LivraisonCommandeFournisseurLigne", "Livraison"); //from item } set { if ((value != null)) { ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection("EasiiDB_001Model.LivraisonCommandeFournisseurLigne", "Livraison", value);//from item } } }
In my main code i have 3 level :
Order => Items => Deliveries
Did you think i have to generate multiple ViewModel classes ?
ObservableCollection and itemsViewModel composed with ObservableCollection ?
In my ViewModel I have
My XamGrid is bind to ObservableCollection Orders
1st ColumnLayout is binding on Items (relationship by model)
2nd ColumnLayout is bind on Deliveries (relationship by model)
I created an example more closer than my developpement.
Thanks a lot for your help