首先,我只是C#的初学者,所以.....不要笑: - )
好的,我的DataTable名为“ 可更改 ”,其中包含列( ID , A , B , C , D , Fdiv )。
A , B , C , D 的值是整数(数字), Fdiv 是带小数点后13位的十进制数, Id 是自动编号。
我有四(4)个计数器(循环),如下面的代码,所有可能的组合数量是21 ^ 4
for ( int A = 10; A <= 31; A++)
{
for ( int B = 10; B <= 31; B++)
{
for ( int C = 10; C <= 31; C++)
{
for ( int D = 10; D <= 31; D++)
{
while (A == 31)
{
Fdiv = A/B * C/D
//Code to fill all 5 values in
// DataTable "Changeable", automatic
}
}
}
}
}
怎么做?
答案 0 :(得分:0)
使用循环填充数据表。
private void AddDataToDGV()
{
DataTable dt = new DataTable();
//create some columns for the datatable
DataColumn dc = new DataColumn("ItemName");
DataColumn dc2 = new DataColumn("ItemValue");
DataColumn dc3 = new DataColumn("Blah");
DataColumn dc4 = new DataColumn("Bleh");
//add the columns to the datatable
dt.Columns.Add(dc);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
//create 5 rows of irrelevant information
//this is the actual answer to your question
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();//create a new row based on the existing "row model"
dr["ItemName"] = "Item" + i + "Name";
dr["ItemValue"] = "Item" + i + "Value";
dr["Blah"] = "Item" + i + "Blah";
dr["Bleh"] = "Item" + i + "Bleh";
dt.Rows.Add(dr);//add the row to the DataTable
}
}