Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CollectionItemChanged not Firing
Message
From
26/03/2013 07:59:19
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01568945
Message ID:
01569226
Views:
25
>>I have a XAML window showing your typical master detail relationship between an Air Waybill (AWB) and the charges on the AWB. The AWB charges are displayed/edited in a grid and there is a textbox on the form which shows the total of the charges in the grid. The textbox is defined like this:
>>
>>
                        <TextBox 
>>                            Name="txtAirWayBillTotal" 
>>                            Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=AirWayBillTotal}"
>>                            Grid.Column="3" 
>>                            Grid.Row="5" 
>>                            Height="23" 
>>                            HorizontalAlignment="Stretch" 
>>                            Margin="0" 
>>                            VerticalAlignment="Top" 
>>                            Width="Auto" 
>>                            Grid.ColumnSpan="2" 
>>                            HorizontalContentAlignment="Right" 
>>                            FontWeight="Bold" IsReadOnly="True" Focusable="False" />
>>
>>
>>The window has the AirWayBillTotal defined like this:
>>
>>
        private decimal airwaybillTotal;
>>
>>        public decimal AirWayBillTotal
>>        {
>>            get
>>            {
>>                return this.airwaybillTotal;
>>            }
>>
>>            set
>>            {
>>                if (value != this.airwaybillTotal)
>>                {
>>                    this.airwaybillTotal = value;
>>                    this.OnPropertyChanged("AirWayBillTotal");
>>                }
>>            }
>>        }
>>
>>
>>I have this code too:
>>
>>
        void AirWayBillDetail_StateChange(mmBaseBusinessObject bizObj, mmBusinessStateChangeEventArgs e)
>>        {
>>            if (e.State == mmBusinessState.Retrieved)
>>            {
>>                // Store the Air WayBill Detail in the DataGrid's data context
>>                this.grdAirWayBillDetails.DataContext = this.AirWayBillDetail.EntityList;
>>
>>                // Hide the new item row place holder in the Air WayBill Detail DataGrid
>>                ((IEditableCollectionView)CollectionViewSource.GetDefaultView(grdAirWayBillDetails.ItemsSource)).NewItemPlaceholderPosition =
>>                    NewItemPlaceholderPosition.None;
>>            }
>>            //this.ShowAirWayBillTotal();
>>            if (this.AirWayBillDetail.EntityList != null)
>>            {
>>                this.AirWayBillTotal = this.AirWayBillDetail.EntityList.Sum(x => x.awd_amount);
>>                foreach (var c in this.AirWayBillDetail.EntityList)
>>                {
>>                    c.PropertyChanged += CollectionItemChanged;
>>                }
>>            }
>>
>>        }
>>
>>which as I understands it will call CollectionItemChanged whenever a value in the EntityList changes (but of course I may be misunderstanding).
>>
>>My CollectionItemChanged code is:
>>
>>
        void CollectionItemChanged(object sender, PropertyChangedEventArgs e)
>>        {
>>            if (e.PropertyName == "awd_amount")
>>            {
>>                AirWayBillTotal = AirWayBillDetail.EntityList.Sum(x => x.awd_amount);
>>                OnPropertyChanged("AirWayBillTotal");
>>            }
>>        }
>>
>>which checks if the value in the entitylist that was changed was awd_amount and if so, re-calculates the total.
>>
>>My problem (finally) is that in certain instances the total does not get updated. This occurs when I add a new row to the charges grid, type in the new amount in the awd_amount column and then use Alt+S to call the Save button's click event. If I tab out of the column the total is updated. It is similar to when using a toolbar in VFP the current control is apparently not losing focus so the change is not registering.
>>
>>Any ideas how to fix this?
>>
>>(Thanks for reading this far!)
>
>Presumably the problem is that updating the grid in the above scenario does not fire the CollectionItemChanged (should be easy to check using a trace) ?
>
>What binding is set on the relevant DataGridTextColumn? If UpdateSourceTrigger is not set to PropertyChanged you could try that.
>
>If you save using the 'Alt-S' is the changed value in the focussed textbox actually saved ? If not then you have a problem even before sorting the totals update.
>Maybe you could monitor for the 'Alt-S' and move the focus from the textbox to trigger the CollectionItemChanged

Hi Viv,

I've got a scenario which I can duplicate. If I set a breakpoint in the CollectionItemChanged code it never gets hit when I add a new row to the grid, select a Charge Type from the combo, then enter an amount. Before I move focus from the amount, I press Alt+N which is the shortcut to the New Charge button. Is that what you meant by "should be easy to check using a trace"?

The grid is defined like this:
                        <DataGrid AutoGenerateColumns="False" Grid.Row="1" Grid.Column="3" 
                                  Height="Auto" 
                                  HorizontalAlignment="Stretch" 
                                  Margin="0" 
                                  Name="grdCourierAirWayBillDetails" 
                                  VerticalAlignment="Stretch" 
                                  Width="Auto" 
                                  IsSynchronizedWithCurrentItem="True" 
                                  ItemsSource="{Binding Mode=default}" 
                                  SelectionMode="Single" 
                                  GridLinesVisibility="None" 
                                  HeadersVisibility="Column" 
                                  Grid.ColumnSpan="2" 
                                 
                                  CanUserAddRows="False" 
                                  CanUserDeleteRows="False" 
                                  SelectionUnit="Cell" 
                                  Grid.RowSpan="4">
                            <DataGrid.Resources>
                                <Style x:Key="AlignRight" TargetType="DataGridCell">
                                    <Setter Property="HorizontalAlignment" Value="Right" />

                                </Style>
                                <Style x:Key="AlignRightHeader" TargetType="DataGridColumnHeader">
                                    <Setter Property="HorizontalAlignment" Value="Right" />
                                </Style>
                            </DataGrid.Resources>
                            <DataGrid.Columns>
                                <DataGridComboBoxColumn Header="Charge Type" Width="2*" 
                                                        DisplayMemberPath="cty_name" 
                                                        SelectedValuePath="cty_pk" 
                                                        SelectedValueBinding="{Binding cwd_ctyfk, Mode=Default}"/>

                                <DataGridTextColumn Header="Amount" Width="*" Binding="{Binding cwd_amount, Mode=default}"
                                                    CellStyle="{StaticResource AlignRight}"
                                                    HeaderStyle="{StaticResource AlignRightHeader}"/>
                            </DataGrid.Columns>
                        </DataGrid>
When I use the Alt+N, then try to save, the values in the grid are not recognised as being stored in the entity list. So there is something strange going on here as the values are fine if I tab out of the amount column.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform