1 回答
TA贡献1830条经验 获得超9个赞
下面将数字放入数据表中。您可以将表格设为datagridview1.DataSource = dt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//create a 1000 strings from numbers starting at 1001
string[] array = Enumerable.Range(1001, 1000).Select(x => "String : " + x.ToString()).ToArray();
var pages = array.Select((x,i) => new {str = x, index = i})
.GroupBy(x => x.index / 112)
.Select(x => x.ToArray())
.ToArray();
var rows = pages
.SelectMany(x => x.GroupBy(y => y.index % 28)).Select(y => y.ToArray())
.ToArray();
DataTable dt = new DataTable();
dt.Columns.Add("Col A", typeof(string));
dt.Columns.Add("Col B", typeof(string));
dt.Columns.Add("Col C", typeof(string));
dt.Columns.Add("Col D", typeof(string));
foreach (var row in rows)
{
DataRow newRow = dt.Rows.Add(new object[] {
row[0].str,
(row.Length > 1) ? (object)row[1].str : null,
(row.Length > 2) ? (object)row[2].str : null,
(row.Length > 3) ? (object)row[3].str : null
});
}
}
}
}
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报