This is a migrated thread and some comments may be shown as answers.

[Solved] TwoWay Binding on a Textbox in a RowDetailsTemplate is not working

3 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
pritesh
Top achievements
Rank 1
pritesh asked on 19 Oct 2010, 06:51 AM
I have telrik grid with another grid in rowdetails template.I have following columns

    Description,
    OrderAmount(Qty),
    TempPrice,
    CurrencyCode
    Total

Total Column is the multiplication of the OrderAmount(Qty) and TempPrice.User can update TempPrice at runtime and based on the new temp price , total must be updated.

I am using Ado.net Entity framework with domain service as a data model. To calculate the total , i have created partial class with following properties as i do not have permission to update entity model.

Description,OrderAmount(Qty) and CurrencyCode are coming ado.net entity framework.While TempPrice and Total are defined in the partial class.

Now my problem is Total is not updated when TempPrice in a column is updated. Following is the code

Grid
<telerikGridView:RadGridView Name="grdOrders" Grid.Row="0" ShowGroupPanel="False" IsReadOnly="False" MinWidth="550"<br>                          AutoGenerateColumns="False" CanUserFreezeColumns="False" RowIndicatorVisibility="Collapsed" <br>                          CanUserResizeColumns="False"  IsFilteringAllowed="False" HorizontalAlignment="Stretch"<br>                          VerticalAlignment="Top" SelectionMode="Single" LoadingRowDetails="grdOrders_LoadingRowDetails" RowDetailsVisibilityChanged="grdOrders_RowDetailsVisibilityChanged" ><br><br>                <telerikGridView:RadGridView.Resources><br>                    <Helper:ArithmeticConverter x:Key="arithmeticconverter"></Helper:ArithmeticConverter><br>                </telerikGridView:RadGridView.Resources><br><br>                <telerikGridView:RadGridView.Columns><br>                    <telerikGridView:GridViewToggleRowDetailsColumn/><br>                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding OrderNumber}" Header="Order Number" Background="HotPink" /><br>                </telerikGridView:RadGridView.Columns><br>                <telerikGridView:RadGridView.RowDetailsTemplate><br>                    <DataTemplate><br>                        <Grid VerticalAlignment="Stretch" ShowGridLines="True" ><br>                            <Grid.RowDefinitions><br>                                <RowDefinition Height="Auto"/><br>                                <RowDefinition Height="Auto"/><br>                            </Grid.RowDefinitions><br>                            <Grid.ColumnDefinitions><br>                                <ColumnDefinition /><br>                            </Grid.ColumnDefinitions><br><br>                            <telerikGridView:RadGridView Name="radgrdOrderDetails" <br>                                ShowColumnFooters="True"<br>                                ShowGroupPanel="False"  <br>                                AutoGenerateColumns="False" <br>                                IsFilteringAllowed="False" <br>                                CanUserFreezeColumns="False"<br>                                RowIndicatorVisibility="Collapsed" <br>                                CanUserResizeColumns="False"  <br>                                HorizontalAlignment="Stretch" <br>                                                    <br>                                VerticalAlignment="Top" Grid.Row="0"><br><br>                                <telerikGridView:RadGridView.Columns><br>                                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Description, Mode=TwoWay}" MinWidth="200"  Header="Description" IsReadOnly="True" IsVisible="True"/><br>                                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding OrderAmount,Mode=TwoWay}" MinWidth="100" Header="Amount" IsReadOnly="True" IsVisible="True"/><br>                                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding TempPrice,Mode=TwoWay}" MinWidth="100" Header="price" IsReadOnly="false" IsVisible="true"/><br>                                    <telerikGridView:GridViewDataColumn  DataMemberBinding="{Binding CurrencyCode,Mode=TwoWay}" MinWidth="100" Header="CurrencyCode" IsReadOnly="True"  /><br><br>                                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Total, Mode=TwoWay}" MinWidth="100" Header="Total" IsReadOnly="True"  ><br>                                        <telerikGridView:GridViewDataColumn.AggregateFunctions><br>                                            <telerikData:SumFunction Caption="Sum : "></telerikData:SumFunction><br>                                        </telerikGridView:GridViewDataColumn.AggregateFunctions><br>                                    </telerikGridView:GridViewDataColumn><br><br>                                </telerikGridView:RadGridView.Columns><br>                            </telerikGridView:RadGridView><br>                        </Grid><br>                    </DataTemplate><br>                </telerikGridView:RadGridView.RowDetailsTemplate><br><br>            </telerikGridView:RadGridView>

Binding the child grid
 
private void grdOrders_LoadingRowDetails(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)<br>        {<br>            objDetailGrid = (RadGridView)e.DetailsElement.FindName("radgrdOrderDetails");<br>            vw_SelectOrderWithInvoice objCurrentItem = (vw_SelectOrderWithInvoice)e.Row.DataContext;<br>            objDetailGrid.ItemsSource = OrderDetails.Where(ord => ord.ID == objCurrentItem.ID);<br>}       <br>

This is how my partial class looks.Main class is defined in ado.net entity framework

public partial class vw_SelectOrderDetails : EntityObject<br>    {<br><br><br>        /// <summary><br>        /// No Metadata Documentation available.<br>        /// </summary><br>        // [EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]<br>        [DataMemberAttribute()]<br>        public global::System.Decimal? Total<br>        {<br>            get<br>            {<br><br>                if (_Total == null)<br>                {<br>                    _Total = Price * OrderAmount;<br>                }<br>                return _Total;<br>            }<br>            set<br>            {<br>                if (Total != value)<br>                {<br>                    OnTotalChanging(value);<br>                    ReportPropertyChanging("Total");<br>                    _Total = StructuralObject.SetValidValue(value);<br>                    ReportPropertyChanged("Total");<br>                    OnTotalChanged();<br>                }<br>            }<br>        }<br>        private global::System.Decimal? _Total;<br>        partial void OnTotalChanging(global::System.Decimal? value);<br>        partial void OnTotalChanged();<br><br>        [DataMemberAttribute()]<br>        public global::System.Decimal? TempPrice<br>        {<br>            get<br>            {<br>                if (_TempPrice == null)<br>                {<br>                    this._TempPrice = Price;<br>                }<br>                return _TempPrice;<br>            }<br>            set<br>            {<br>                if (_TempPrice != value)<br>                {<br>                    OnTempPriceChanging(value);<br>                    ReportPropertyChanging("TempPrice");<br>                    _TempPrice = StructuralObject.SetValidValue(value);<br>                    ReportPropertyChanged("TempPrice");<br>                    OnTempPriceChanged();<br>                    Price = _TempPrice;<br>                    Total = _TempPrice * OrderAmount;<br>                    ReportPropertyChanged("Total");<br>                }<br>            }<br>        }<br>        private global::System.Decimal? _TempPrice;<br>        partial void OnTempPriceChanging(global::System.Decimal? value);<br>        partial void OnTempPriceChanged();<br><br><br><br><br>    }

Please help me.

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 19 Oct 2010, 09:06 AM
Hello pritesh,

A similar scenario to yours is described and demonstrated in this blog post. As you may read at the bottom of the article, you can benefit from the INotifyPropertyChanged Interface. In case you implement it, you will be able to change the value of some of the columns and the result in the calculated column will be updated. Furthermore, you can download a sample project demonstrating this approach.

Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
pritesh
Top achievements
Rank 1
answered on 19 Oct 2010, 09:34 AM
Thanks for your quick reply.I already have reviewed the given blog before i post the forum. This does not serve the purpose.I do not want to use IConverter as i need to perform certain calculation based on the price range.
Also If you see vw_SelectOrderDetails : EntityObject part ,EntityObject itself have implemented INotifyPropertyChanged.


0
Maya
Telerik team
answered on 20 Oct 2010, 04:40 PM
Hi pritesh,

Another possible approach may be to recalculate the "Total" property, once the value of other properties have been changed. I am sending you a sample project illustrating this approach.
 

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
pritesh
Top achievements
Rank 1
Answers by
Maya
Telerik team
pritesh
Top achievements
Rank 1
Share this question
or