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

[Solved] Update Binding on calculated values

3 Answers 134 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.
Berthold
Top achievements
Rank 1
Berthold asked on 27 Sep 2010, 11:24 AM
Hi, 
I use the RadGridView to show a list of items, get from DomainDataSource (List of TRoom objects, where TRoom has two properties: Seats and OccupiedSeats) 
 
The Grid contains
- Seats
- Occupied
- FreeSeats (which is calculated: Seats - OccupiedSeats, done by a converter)

Loading works perfect, but when I change the OccupiedSeats, the FreeSeats are not calculated.

CodeSnippet:
XAML:
 <riaControls:DomainDataSource x:Name="myDataSource".../>
....
<!-- The Grid bound the values -->
<Controls:RadGridView  ItemsSource="{Binding Data, ElementName=myDataSource}"  .....>
  <Controls:GridViewDataColumn DataMemberBinding="{Binding Seats}" />
        <Controls:GridViewDataColumn DataMemberBinding="{Binding OccupiedSeats}" />
        <Controls:GridViewDataColumn DataMemberBinding="{Binding  Converter={StaticResource localCalcFreeSeats}, ConverterParameter=Free}" Header="Free Seats"/>
</Controls:RadGridView>

In a Dataform (on the same page) I chnage the values. 
When "Seats" or "OccupiedSeats" are changed by the DataForm, this will update the GridView as well. 
But the Converter is not called.

As far as I know, Multibinding is not possible in Silverlight. 
So is there a way to enforce Binding, even when no Path-value is defined?

Thanks
Berthold




3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 27 Sep 2010, 03:09 PM
Hello Berthold,

A clean solution would be  ( using the INotifyPropertyChanged interface) to bind the calculated field to  the FreeSeats property.

Then modify your TRoom  class to raise the PropertyChanged event for the FreeSeats whenever it is recalculated.
RadGridView will update the UI whenever it receives a property changed notification.

Regards,
Pavel Pavlov
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
Berthold
Top achievements
Rank 1
answered on 27 Sep 2010, 03:28 PM
Hi Pavel,

thanks for your feedback.
I'm using the MVVM-concept. So calling PropertyChange event is possible.
But I have no idea, which property I should call: PropertyChange("which one to call?").
"FreeSeats" is not a property of my class!

Since I'm working with EntityFramework, the members of the TRoom class are predefined through the database (Table Room).
So I can't add a new member without adding a new table column in my database.

And in my XAML I'm not using path, because I want access the TRoom-class inside the converter:
<Controls:GridViewDataColumn DataMemberBinding="{Binding  <!--no path here--> Converter={StaticResource localCalcFreeSeats}, ConverterParameter=Free}" Header="Free Seats"/>

CodeSnippet of my converterClass:

 

 

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

 

{

 

 

   if (value == null || parameter == null)

 

 

 

    return "";

 

 

 

  TRoom room = value as TRoom;

 

     return room.Seats - room.OccupiedSeats;  
}

Thanks
Berthold

By the way: TRoom is only an example, the real code is a bit more complex.
0
Pavel Pavlov
Telerik team
answered on 30 Sep 2010, 03:29 PM
Hi Berthold,

EntityFramework provides a standard approach for cases like yours. The authors have estimated that you may need to extend the generated class - in your case TRoom. So you will notice that this class is declared partial.
This means you can add the FreeSeats property  to the TRoom class.
When you raise the PropertyChanged event, you shall pass the "FreeSeats" property in the args.

A similar topic is discussed here.

In case you have troubles implementing this ,let me know and will be glad to provide further assistance.

Sincerely yours,
Pavel Pavlov
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
Berthold
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Berthold
Top achievements
Rank 1
Share this question
or