简体   繁体   English

C#我想使用循环语句在Datagridview中添加Value数据

[英]C# I want to add the Value data in datagridview with looping statement

hi, I want to add the value data in datagridview of this code; 嗨,我想在此代码的datagridview中添加值数据;

int tsp;
double mf, tcp, interest, disc;
int a, b;
double MP;

if (comboBox1.Text == "Deferred Cash Payment in 2 years at 0% interest")
{
 a = int.Parse(textBox3.Text);
 b = int.Parse(textBox4.Text);
 tsp = a * b;

 mf = tsp * 0.07;
 tcp = mf + tsp;
 label8.Text = tcp.ToString("₱000,000.00");

 MP = tcp / 24;

the MP variables has a data; MP变量具有数据; and i want to show it in datagridview with looping statement with 24 rows. 我想在带有24行循环语句的datagridview中显示它。 and i want the output like this: 我想要这样的输出:

ex. 例如

Days  Amount
1     10,000
2     10,000
3     10,000
4     10,000
5     10,000
..
24    10,000

In windows forms application you can create a new DataTable instance and bind that DataTable to DataGridView like this; 在Windows窗体应用程序中,您可以创建一个新的DataTable实例,并将该DataTable绑定到DataGridView,如下所示;

Your values should appear to your DataGridView. 您的值应显示在您的DataGridView中。 Your changes will be direct to the DataGridView. 您所做的更改将直接发送到DataGridView。

    DataTable dt = new DataTable();
    dt.Columns.Add("Days", typeof(int));
    dt.Columns.Add("Amount", typeof(decimal));

    dt.Rows.Add(1, 10.00m);
    dt.Rows.Add(2, 10.00m);
    dt.Rows.Add(3, 10.00m);
    dt.Rows.Add(4, 10.00m);
    dt.Rows.Add(5, 10.00m);

    dt.Rows.Add(24, 10.00m);

    dataGridView1.DataSource = dt;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM