如何在datagridview中表示?

时间:2014-10-29 22:02:39

标签: c# datagridview

我有一个类,我在其中进行了所有计算,现在我想在datagridview中表示这个数据我应该用c#做什么? 我做了什么,但它不起作用

for (int i = 1; i <= cust_num; i++)
{
    dataGridView1.Rows.Add();
    dataGridView1.Rows[i].Cells["Customer_Number"].Value = cust_num.ToString();
    dataGridView1.Rows[i].Cells["Time_between_Arrival"].Value = inter_Arrival_time.ToString();
    dataGridView1.Rows[i].Cells["service_Time"].Value = service_Time.ToString();
    dataGridView1.Rows[i].Cells["Arrival_Time"].Value = rand_inter_Arrival.ToString();
    dataGridView1.Rows[i].Cells["Time_Service_Beg"].Value = Arrival_Time.ToString();
    dataGridView1.Rows[i].Cells["ServiceNum"].Value = service_number.ToString();
    dataGridView1.Rows[i].Cells["service_Time"].Value = rand_service_time.ToString();
    dataGridView1.Rows[i].Cells["Time_service_End"].Value = finsh_time.ToString();
    dataGridView1.Rows[i].Cells["Waiting_Time"].Value = waiting_time.ToString();
   // dataGridView1.Rows.Add(row);
}

1 个答案:

答案 0 :(得分:0)

string[] row = new string[] { cust_num.ToString(), inter_Arrival_time.ToString(), ...... };
dataGridView1.Rows.Add(row);

您可以像这样

向datagridview添加行