Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi guys. how to calculate the two input columns values to Display a Total column in a same DataGrid in a runtime. which event is best event to calculate the grid value. plz help me..

What I have tried:

XML
<DataGrid x:Name="dgArrearPost" HorizontalAlignment="Left" Background="White" AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" Margin="283,317,0,0" VerticalAlignment="Top" Height="288" Width="563" KeyDown="dgArrearPost_KeyDown" KeyUp="dgArrearPost_KeyUp" CellEditEnding="dgArrearPost_CellEditEnding" SelectedCellsChanged="dgArrearPost_SelectedCellsChanged">
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Effect>
<DropShadowEffect/>
</DataGrid.Effect>
<DataGrid.Columns>
<DataGridTextColumn Header="Subject1" FontWeight="Bold" Width="100" Binding="{Binding Subject1,ValidatesOnExceptions=True,StringFormat=d }" />
<DataGridTextColumn Header="Subject2" FontWeight="Bold" Width="100" Binding="{Binding Subject2,ValidatesOnExceptions=True,StringFormat=d}" IsReadOnly="False" />
<DataGridTextColumn Header="Subject3" FontWeight="Bold" Width="100" Binding="{Binding Subject3,ValidatesOnExceptions=True,StringFormat=d }" IsReadOnly="False" />
<DataGridTextColumn Header="Total" FontWeight="Bold" Width="100" Binding="{Binding Total,ValidatesOnExceptions=True,StringFormat=d }" IsReadOnly="False" />
</DataGrid.Columns>
</DataGrid>
 
 
private void dgSubject_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.EditAction == DataGridEditAction.Commit)
{
var column = e.Column as DataGridBoundColumn;
if (column != null)
{
var bindingPath = (column.Binding as Binding).Path.Path;
else if (bindingPath == "Subject1")
{
var el = e.EditingElement as TextBox;
if (el!=null)
{
// How to Calculate the Subject1,Subject2,Subject3 Columns 
}
}
}
}
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900