C# 合并GriewView相同列的小例子
程序员文章站
2023-12-09 18:46:45
复制代码 代码如下: /// /// 合并gridview中某列相同信息的行(单元格) &n...
复制代码 代码如下:
/// <summary>
/// 合并gridview中某列相同信息的行(单元格)
/// </summary>
/// <param name="gridview1"></param>
/// <param name="cellnum"></param>
public static void groupcol(gridview gridview1, int cols)
{
if (gridview1.rows.count < 1 || cols > gridview1.rows[0].cells.count - 1)
{
return;
}
tablecell oldtc = gridview1.rows[0].cells[cols];
for (int i = 1; i < gridview1.rows.count; i++)
{
tablecell tc = gridview1.rows[i].cells[cols];
if (oldtc.text == tc.text)
{
tc.visible = false;
if (oldtc.rowspan == 0)
{
oldtc.rowspan = 1;
}
oldtc.rowspan++;
oldtc.verticalalign = verticalalign.middle;
}
else
{
oldtc = tc;
}
}
}