C# .NET - Computed Columns In WPF DataGrid
Asked By krutik sheth
01-Apr-11 09:37 AM

hie,
I want to created computed columns like ms excel in wpf customized
datagrid.Can anyone suggest some idea.for eg i have datagrid in
following format:
<DataGrid Name="dgv" Grid.Row="1" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Name="grdCell">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--<TextBox Name="tempTotal" Grid.Row="0"
Grid.Column="0" IsReadOnly="True" Focusable="False"
Visibility="Collapsed">
<TextBox.Text>
<Binding Path="tempTotal" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay"></Binding>
</TextBox.Text>
</TextBox>-->
<TextBox Name="txtDays" Grid.Row="0" Grid.Column="1" IsReadOnly="True" Focusable="False">
<TextBox.Text>
<Binding Path="days" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" ></Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="txttank1" Grid.Row="0" Grid.Column="2" Background="Yellow">
<TextBox.Text>
<Binding Path="tank1" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" ></Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="txttank2" Grid.Row="0" Grid.Column="3" Background="Yellow">
<TextBox.Text>
<Binding Path="tank2" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" ></Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="txttank3" Grid.Row="0" Grid.Column="4" Background="Yellow">
<TextBox.Text>
<Binding Path="tank3" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" ></Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="txttank4" Grid.Row="0" Grid.Column="5" Background="Yellow">
<TextBox.Text>
<Binding Path="tank4" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" ></Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="txttank5" Grid.Row="0" Grid.Column="6" Background="Yellow">
<TextBox.Text>
<Binding Path="tank5" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" ></Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="txttotalOilStock" Grid.Row="0" Grid.Column="7" IsReadOnly="True" Focusable="False">
<TextBox.Text>
<Binding Path="total_oil_stock"
UpdateSourceTrigger="PropertyChanged" Mode="OneWay" ></Binding>
</TextBox.Text>
</TextBox>
<Button Name="btnNew" Grid.Column="8" Content="New" Click="btnNew_Click"></Button>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
there are 5 textbox with name tank1,tank2,tank3,tank4,tank5.Now what i
want is in 6th textbox name total i want summation of all tank from 1 to
5.Its like i want to call text change property of each five textbox
which reflect changes made in textbox named total.
Robbe Morris replied to krutik sheth
The proper way to do this sort of thing with WPF and Silverlight is to create properties on your data class that display these totals. You'd wire up code using the INotifyPropertyChanged handler interface which triggers recalculation anytime one of the other textboxes changes.

A Custom ASP.NET Silverlight 5.0 RIA Services DomainService with Dapper-Dot-Net Silverlight RIA Services has undergone steady improvements, and it is included With Silverlight 5.0. WCF RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. RIA Services provides a pattern to write application logic that runs on the mid end support for common tasks such as data validation, authentication and roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier. It's easy to such as Dapper, you need to derive your class from DomainService. To work with the Silverlight client, a DomainService must be decorated with the EnableClientAccess attribute. You add methods to your all the columns in the Northwind Employees table in this class. When you create your Silverlight Solution, remember to check the box "Enable RIA Services". I'll be using a DataGrid with a DomainDataSource control, which is preconfigured to be able to work with a DomainService
drag and drop row in silverlight datagrid Silverlight / WPF hi. . how to drag and drop row in silverlight datagrid? need ur suggestions with examples. . regards gopal.s Silverlight 2 Solution The first problem you will encounter in Silverlight 2 is determining how / when to initiate the drag operation. The most obvious route is to attach to the MouseLeftButtonDown event of the DataGridRow during the DataGrid.LoadingRow event, unfortunately the MouseLeftButtonDown event never fires! (Bear in mind the mouse must be
WPF DataGrid Custom Paging and Sorting This article shows how to implement custom paging and sorting on a WPF DataGrid. Introduction WPF DataGrid has built-in functionality for sorting its items by clicking on a column header. However it only works for the current items in the DataGrid. This becomes a problem when paging functionality is implemented. Paging is a must when items of products and buttons for moving through the list. The data grid is a WPF DataGrid. It is not yet a released product but is downloadable from CodePlex under WPF Toolkit xmlns : tk = "http: / / schemas.microsoft.com / wpf / 2008 / toolkit" Width = "350" Height = "190" Title = "WPF DataGrid Paging and Sorting"> < Grid > < Grid.RowDefinitions > < RowDefinition Height = "*" / > < RowDefinition Height = "Auto" / > < / Grid.RowDefinitions > < tk : DataGrid AutoGenerateColumns = "False" IsReadOnly = "True" ItemsSource = "{ Binding Products }"> < tk : DataGrid.Columns > < tk : DataGridTextColumn Header = "PRODUCT ID" Binding = "{ Binding Id }" Width = "*" / > < tk : DataGridTextColumn Header = "PRODUCT NAME
WPF DataGrid as ComboBox Dropdown This article describes how to display the items of a WPF ComboBox inside a DataGrid when the ComboBox is clicked. It also shows how to make the behavior same as that of a normal ComboBox, like clicking the item on the DataGrid should close the ComboBox's popup. WPF DataGrid as ComboBox Dropdown I had a WPF application wherein I want to display a list item as columns and the items as rows. Fortunately, I found out about the WPF DataGrid. I decided to use the DataGrid to show the items when the ComboBox is clicked. First things first. Since the WPF DataGrid is not officially released yet at this time, so you need to download the latest WPFToolkit binaries from CodePlex - http: / / wpf.codeplex.com / . The DataGrid is part of the WPFToolkit library. The library has other useful controls as well. After