Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to calculate totals of wpf datagrid column with dataset which is created by adding a DataTemplate in Resources?

$
0
0

I am trying to figure out what is the best way to calculate a total value of DataGrid column in wpf, I´m using dataset to display data from SQL server in my Resources(DataTemplate) & bind it to datagrid like below:

DataTemplate:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    x:Class="AgamistaStore.Resources.DataTemplatesClass"
                     xmlns:myClasses="clr-namespace:AgamistaStore.Classes"><myClasses:TablesStateConverter  x:Key="TablesStateConverter"/><myClasses:OrderItemNotEditableStateConverter x:Key="NotEditableStateConverter"/><!-- ProductName column --><DataTemplate x:Key="NotEditableStateColumnTemplate"><Image Height="20" Width="20" Source="{Binding Path=NotEditable, 
                Converter={StaticResource NotEditableStateConverter}, Mode=Default}" HorizontalAlignment="Stretch"/></DataTemplate><!-- Barcode column --><DataTemplate x:Key="ProductBarcodeColumnTemplate"><TextBlock  FontFamily="Tahoma" FontSize="14" Text="{Binding Path=ProductBarcode}" HorizontalAlignment="Stretch"
                    Foreground="#FF44544A" /></DataTemplate><!-- ProductName column --><DataTemplate x:Key="ProdNameColumnTemplate"><TextBlock  FontFamily="Tahoma" FontSize="14" Text="{Binding Path=ProductName}" HorizontalAlignment="Stretch"
                    Foreground="#FF44544A"/></DataTemplate><!-- Price column --><DataTemplate x:Key="PriceNameColumnTemplate"><TextBlock x:Name="SalePrice" FontFamily="Tahoma" FontSize="14" HorizontalAlignment="Stretch" 
                   Text="{Binding Path=SalePrice, StringFormat={}{0:#.##}}" Foreground="#FF44544A"/></DataTemplate><!-- Quntity column --><DataTemplate x:Key="QuntityColumnTemplate"><TextBox x:Name="txtQuntity" Tag="{Binding}" PreviewTextInput="txtQuntity_PreviewTextInput" 
                      Style="{StaticResource TextBoxStyle}" Height="20"  Foreground="#FF0A421F" 
                     FontFamily="Tahoma" FontSize="14"  Text="{Binding Path=SoldQuantity}" HorizontalAlignment="Stretch"/></DataTemplate></ResourceDictionary>

MainWindow:

<Border Grid.Column="1" CornerRadius="6,6,6,6" BorderThickness="1,1,1,1" BorderBrush="#FFBCC7BB" 
                        Margin="9,10,8,10" x:Name="borderDetails"><Grid HorizontalAlignment="Left" Width="439" Margin="0,0,0,0" VerticalAlignment="Top" 
                      Height="397" Visibility="Visible"><Grid.RowDefinitions><RowDefinition Height="352*" /><RowDefinition Height="45*" /></Grid.RowDefinitions><!--bill details --><myClasses:SortableListView Margin="9,6,6,0" Height="auto" BorderBrush="{x:Null}"
			                      Background="{x:Null}"   ScrollViewer.VerticalScrollBarVisibility="Auto"
			                      ScrollViewer.HorizontalScrollBarVisibility="Auto" AllowDrop="True" 
			                      VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="True"
			                      SelectionMode="Single"  IsSynchronizedWithCurrentItem="True"
			                      ItemContainerStyle="{DynamicResource RestaurantEditListViewItemStyle}"
			                      Style="{DynamicResource RestaurantEditListViewStyle}" IsEnabled="True" 
                                  HorizontalAlignment="Stretch" VerticalAlignment="Top" x:Name="gvOrderDetails" ><myClasses:SortableListView.View><GridView AllowsColumnReorder="False" ><GridViewColumn Width="4" 
                                           HeaderContainerStyle="{DynamicResource FirstColumnGridViewColumnHeader}" 
                                           CellTemplate="{StaticResource EmptyColumnTemplate}"/><GridViewColumn Width="8" CellTemplate="{StaticResource NotEditableStateColumnTemplate}" 
                                        HeaderContainerStyle="{DynamicResource RestaurantDataGridViewColumnHeader}"/><myClasses:SortListViewColumn Header="كود الصنف" SortProperty="ProductBarcode" 
                                         Width="80" CellTemplate="{StaticResource ProductBarcodeColumnTemplate}"  
                                         SortStyle="RestaurantDataGridViewColumnHeader" 
                                         HeaderContainerStyle="{DynamicResource RestaurantDataGridViewColumnHeader}" /><myClasses:SortListViewColumn Header="اسـم الـصـنـف" SortProperty="ProductName" 
                                         Width="200" CellTemplate="{StaticResource ProdNameColumnTemplate}"  
                                         SortStyle="RestaurantDataGridViewColumnHeader" 
                                         HeaderContainerStyle="{DynamicResource RestaurantDataGridViewColumnHeader}" /><myClasses:SortListViewColumn Header="السعر"  SortProperty="SalePrice"
                                         CellTemplate="{StaticResource PriceNameColumnTemplate}" 
                                         Width="60" SortStyle="RestaurantDataGridViewColumnHeader" 
                                         HeaderContainerStyle="{DynamicResource RestaurantDataGridViewColumnHeader}" /><myClasses:SortListViewColumn Header="الكمية"  SortProperty="UnitName" Width="50" 
                                         CellTemplate="{StaticResource QuntityColumnTemplate}" 
                                         SortStyle="RestaurantDataGridViewColumnHeader" 
                                         HeaderContainerStyle="{DynamicResource RestaurantDataGridViewColumnHeader}"/><GridViewColumn Width="4" CellTemplate="{StaticResource EmptyColumnTemplate}" 
                                         HeaderContainerStyle="{DynamicResource LastColumnGridViewColumnHeader}"/></GridView></myClasses:SortableListView.View></myClasses:SortableListView>

Now I want to get the total sum (which is sum(SalePrice*SoldQuantity)  to display in textbox, And SoldQuantity value can changed by user

What is the best practice to do this ?

Thanks,




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>