SADAM  HUSSAIN

SADAM HUSSAIN

  • NA
  • 65
  • 4.3k

How to get a total colum from two input column in DataGrid

Dec 20 2016 6:42 AM
hi guys. how to calculate the two input columns values to Total column. plz help me..
<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 
}
}
}
}
}
 
 
 
 

Answers (3)