我认为这可以帮助你
DataTable dtDataSource = new DataTable();
dtDataSource.Columns.Add("A");
dtDataSource.Columns.Add("B");
dtDataSource.Columns.Add("C");
dtDataSource.Rows.Add(new object[] { "1", "1", "1" });
dtDataSource.Rows.Add(new object[] { "1", "1", "2" });
dtDataSource.Rows.Add(new object[] { "1", "1", "3" });
dtDataSource.Rows.Add(new object[] { "2", "1", "1" });
dtDataSource.Rows.Add(new object[] { "2", "1", "2" });
dtDataSource.Rows.Add(new object[] { "2", "1", "3" });
DataTable dtNew = dtDataSource.Clone();
for (int i = 0; i < dtDataSource.Rows.Count; i++)
{
if (i > 0)
{
if (dtDataSource.Rows[i][0].Equals(dtDataSource.Rows[i - 1][0]))
{
dtNew.Rows.Add(new object[] { "", dtDataSource.Rows[i][1], dtDataSource.Rows[i][2] });
}
else
{
dtNew.Rows.Add(new object[] { dtDataSource.Rows[i][0], "", "" });
dtNew.Rows.Add(new object[] { "", dtDataSource.Rows[i][1], dtDataSource.Rows[i][2] });
}
}
else
{
dtNew.Rows.Add(new object[] { dtDataSource.Rows[i][0], "", "" });
dtNew.Rows.Add(new object[] { "", dtDataSource.Rows[i][1], dtDataSource.Rows[i][2] });
}
}
dataGridView1.DataSource = dtNew;
您的数据应首先订购。
我试图在这里转换 VB.Net