Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Two way binding requires Path or XPath
Message
De
19/02/2013 07:48:26
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Two way binding requires Path or XPath
Versions des environnements
Environment:
C# 4.0
Divers
Thread ID:
01566360
Message ID:
01566360
Vues:
66
***** SOLVED! ***** the crt_amount should have been crt_Amount (note the capital A)

Hi,

I have a datagrid defined like this:
                       <DataGrid AutoGenerateColumns="False" Grid.Row="4" Grid.Column="1" 
                                  Height="Auto" 
                                  HorizontalAlignment="Stretch" 
                                  Margin="0" 
                                  Name="grdCashReceipts" 
                                  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="2" CellEditEnding="grdCashReceipts_CellEditEnding" 
                                  AlternatingRowBackground="LightGray">
                            <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>
                                <DataGridTextColumn Header="Invoice #"
                                                    Width="*" 
                                                    Binding="{Binding crt_invfk, Converter={StaticResource Inv_PkToNumberConverter}}"                                                     
                                                    x:Name="txtInv_Number" IsReadOnly="False"/>

                                <DataGridTextColumn Header="Invoice Date" 
                                                    Width="*" 
                                                    Binding="{Binding crt_invfk, Converter={StaticResource Inv_PkToInvoicePropertyConverter}, 
                                                              ConverterParameter='inv_date', Mode=OneWay, StringFormat=d}"
                                                    IsReadOnly="True"/>

            
                                <DataGridTextColumn Header="Amount" 
                                                    Width="*" 
                                                    Binding="{Binding crt_amount, Mode=default}"
                                                    CellStyle="{StaticResource AlignRight}"
                                                    HeaderStyle="{StaticResource AlignRightHeader}"/>
                                
                            </DataGrid.Columns>
                        </DataGrid>
After I enter a value in the Amount column and try to move from the textbox, I get the error: Two way binding requires Path or XPath.

Anyone have any idea what I am missing or have done wrong?

A bit more info:

The error occurs in this code:
        private void grdCashReceipts_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            if (!this.manualEditEnding)
            {
                this.manualEditEnding = true;

                if (this.CashReceipt.Entity.crt_invfk == null || this.CashReceipt.Entity.crt_invfk == Guid.Empty)
                {
                    // need to make sure we are on a textbox and that we are on the txtinv_number textbox
                    var editedTextbox = e.EditingElement as TextBox;

                    if (editedTextbox != null)
                    {
                        string invNumber = editedTextbox.Text;
                        int invoiceNumber = 0;
                        bool result = Int32.TryParse(invNumber, out invoiceNumber);
                        if (invoiceNumber > 0)
                        {
                            InvoiceEntity invoice = this.InvoiceLookup.GetAvailableInvoiceByNumber(invoiceNumber);   //this.CashReceipt.Entity.inv_number);

                            if (invoice.inv_pk == Guid.Empty)
                            {
                                mmAppWPF.MessageBox.Show("This Invoice either does not exist or payment was already received.",
                                           "New Receipt",
                                           MessageBoxButton.OK,
                                           MessageBoxImage.Information);
                                editedTextbox.Text = "0";
                            }
                            else
                            {
                                this.CashReceipt.Entity.crt_invfk = invoice.inv_pk;
                            }
                            //this.CashReceipt.Entity.inv_date = invoice.inv_date;
                        }
                    }
                }

                this.grdCashReceipts.CommitEdit(DataGridEditingUnit.Row, true);
                this.manualEditEnding = false;

            }
        }
The error occurs on this line in the above code:

this.grdCashReceipts.CommitEdit(DataGridEditingUnit.Row, true);
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Répondre
Fil
Voir

Click here to load this message in the networking platform