Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,768 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I have an amortization example for Personal Loan like this;
I want to implement this using datagrid. so I wrote following code:
<DataGrid x:Name="AmortizTable" ItemsSource="{Binding Amortable}" AutoGenerateColumns="False" Grid.Row="1">
<DataGrid.Resources>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="HorizontalContentAlignment" Value="Right"/>
<Setter Property="Width" Value="90"/>
</Style>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Width" Value="90"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="Term" Binding="{Binding Terms}" IsReadOnly="True"/>
<DataGridTextColumn Header="Principal" Binding="{Binding Principal}" IsReadOnly="True"/>
<DataGridTextColumn Header="Interest" Binding="{Binding Interest}" IsReadOnly="True"/>
<DataGridTextColumn Header="Payment" Binding="{Binding Payment}" IsReadOnly="True" />
<DataGridTextColumn Header="Balance" Binding="{Binding Balance}" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
//create datatable and add column
Amortable = new DataTable();
Amortable.Columns.Add("Terms", typeof(int));
Amortable.Columns.Add("Principal", typeof(double));
Amortable.Columns.Add("Interest", typeof(double));
Amortable.Columns.Add("Payment", typeof(double));
Amortable.Columns.Add("Balance", typeof(double));
//insert row at first row
DataRow row = Amortable.NewRow();
row["Balance"] = Math.Ceiling(Convert.ToDouble(off.LoanAmt));
row["Terms"] = 0;
row["Payment"] = 0.0;
row["Interest"] = 0.0;
row["Principal"] = 0.0;
Amortable.Rows.InsertAt(row, 0);
//add row
for (int i = 0; i <Convert.ToInt32(off.Terms) * 12; i++)
{
DataRow dataRow = Amortable.NewRow();
dataRow["Terms"] = i + 1;
dataRow["Payment"] = Math.Ceiling(Convert.ToDouble(off.Payment));
dataRow["Interest"] = Math.Ceiling(Convert.ToDouble(off.APR) / 12 / 100 * Convert.ToDouble(Amortable.Rows[i].Field<double>("Balance")));
dataRow["Principal"] = Math.Ceiling(Convert.ToDouble(dataRow["Payment"]) - Convert.ToDouble(dataRow["Interest"]));
dataRow["Balance"] = Math.Ceiling(Convert.ToDouble(Amortable.Rows[i]. Field<double>("Balance")) - Convert.ToDouble(dataRow["Principal"]));
if (Convert.ToDouble(dataRow["Balance"]) < 0.0)
dataRow["Balance"] = 0.0;
Amortable.Rows.Add(dataRow);
}
after running above code, I thought above code work, but I want to add thousand separators to the data in datagrid, so I add following as a test: c00012