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

Calculation in Details Row

4 Answers 64 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 22 Apr 2011, 10:43 PM
I have a RGV with a calculatedcolumn working from an expression in code behind

(dg_tblPOLines.Columns["ex_Poundage"] as GridViewExpressionColumn).Expression = exp;

this is working great.  I want to "move" this calculation to a TextBlock in the details row and depricate the GVExpressionColumn.  The datatemplate for the details row is below and the TextBlock is "txt_EF_Price". 

This calculation is from Bindings on the details row and is simply basePrice - diffPrice 
<UserControl x:Class="RoasterWerks.DataTemplates.POItemDetailTemplate"
      
    <Grid Width="Auto" HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="20"/>
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="60" />
            <ColumnDefinition Width="20" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="30" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="30" />
            <ColumnDefinition Width="20" />
        </Grid.ColumnDefinitions>
        <TextBlock Text="Base Price: " Margin="5,0,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <TextBlock Text="{Binding basePrice, StringFormat=\{0:$##0.0000\}}" Margin="5,0,5,0" Grid.Row="0" Grid.Column="2"  VerticalAlignment="Center" HorizontalAlignment="Left"/>
        <TextBlock Text="Differential: " Margin="5,0,0,0" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <TextBlock Text="{Binding diffPrice, StringFormat=\{0:$##0.0000\}}" Margin="5,0,5,0" Grid.Row="1" Grid.Column="2"  VerticalAlignment="Center" HorizontalAlignment="Left"/>
        <TextBlock Text="Effective Price: " FontWeight="Bold" Margin="5,0,0,0" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <TextBlock  x:Name="txt_EF_Price" Margin="5,0,0,0" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Left"/>
  
        <Border Grid.Column="3" Grid.Row="0" Grid.RowSpan="3" Width="1" Background="#FFA0AFC3" VerticalAlignment="Stretch" HorizontalAlignment="Center" Margin="0,10" />
  
        <TextBlock Text="Certifications" FontWeight="Bold" Grid.Row="0" Grid.Column="4" Grid.ColumnSpan="4" HorizontalAlignment="Center" />
        <TextBlock Text="Exchange: " Margin="5,0,0,0" Grid.Row="1" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <Image Source="{Binding isCert, Converter={StaticResource BoolToImageConverter}}" Grid.Column="5" Grid.Row="1"/>
        <TextBlock Text="Fair Trade: " Margin="5,0,0,0" Grid.Row="2" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <Image Source="{Binding isFairTrade, Converter={StaticResource BoolToImageConverter}}" Grid.Column="5" Grid.Row="2"/>
        <TextBlock Text="Organic: " Margin="5,0,0,0" Grid.Row="1" Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <Image Source="{Binding isOrganic, Converter={StaticResource BoolToImageConverter}}" Grid.Column="7" Grid.Row="1"/>
        <TextBlock Text="Rainforest: " Margin="5,0,0,0" Grid.Row="2" Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Left" />
        <Image Source="{Binding isRainForest, Converter={StaticResource BoolToImageConverter}}" Grid.Column="7" Grid.Row="2"/>
          
        <Border Grid.Column="8" Grid.Row="0" Grid.RowSpan="3" Width="1" Background="#FFA0AFC3" VerticalAlignment="Stretch" HorizontalAlignment="Center" Margin="0,10" />
          
    </Grid>
</UserControl>

Thank you for your help.

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Apr 2011, 09:28 AM
Hello Mark,

Yo can display the final result the following way:

Place a text box in the details template . Bind it directly to the context e.g. <TextBox Text={Binding} ...
To perform the calculation you will need to create a small  converter for the binding ( IValueConverter ) .
e.g.
<TextBox Text={Binding, Converter = {Static Resource MyConverter} ...

Inside the Convert method of the converter  you do the calculation.
Let me know in case you need additional assistance on this one.

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
Mark
Top achievements
Rank 1
answered on 25 Apr 2011, 07:17 PM
Hi Pavel,

Yes, some sort of example / sample would be very helpful as I don't know how to pass the properties to the IConverter as they aren't the "cell" in question.  As per my original post, they are basePrice and diffPrice.  Many thanks!
0
Accepted
Maya
Telerik team
answered on 26 Apr 2011, 08:18 AM
Hello Mark,

The value in the converter will be of type your business object. Consequently, you may do something similar to:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var currentPlayer = value as Player;
            return (currentPlayer.Number * currentPlayer.Number1).ToString();
        }

In this case the business object is Player and it exposes Number and Number1 properties. Still I am sending you a sample project so that you may use it for further reference. Please let me know in case you need any additional assistance.
 


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
Mark
Top achievements
Rank 1
answered on 26 Apr 2011, 11:36 AM
Thanks so much!  Just what I needed.  This was the approach I took and it confirms what I needed.
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mark
Top achievements
Rank 1
Maya
Telerik team
Share this question
or