1.栏位枚举
private enum DataGridColumn
{
ROWNUM = ,
EMPID,
EMPNAME,
SEX,
SALARY,
ADRRESS,
PHONE,
TEL,
POSITIION,
REMARK
}
2.合并函数
private void SpanRow(DataGrid dg)
{
int i = ;
int j = ;
int rowNum = ;//序号
int rowSpan;
string SEX = ""; //相同SEX,合并SEX单元格
for (i = ; i < dg.Items.Count; i++)
{
rowSpan = ;
SEX = dg.Items[i].Cells[(int)DataGridColumn.SEX].Text;
for (j = i + ; j < dg.Items.Count; j++)
{
if (string.Compare(SEX, dg.Items[j].Cells[(int)DataGridColumn.SEX].Text) == )
{
rowSpan += ;
dg.Items[i].Cells[(int)DataGridColumn.SEX].RowSpan = rowSpan;
dg.Items[j].Cells[(int)DataGridColumn.SEX].Visible = false;
dg.Items[i].Cells[(int)DataGridColumn.EMPNAME].RowSpan = rowSpan;
dg.Items[j].Cells[(int)DataGridColumn.EMPNAME].Visible = false;
dg.Items[i].Cells[(int)DataGridColumn.EMPNAME].RowSpan = rowSpan;
dg.Items[j].Cells[(int)DataGridColumn.EMPNAME].Visible = false;
dg.Items[i].Cells[(int)DataGridColumn.ROWNUM].RowSpan = rowSpan;
dg.Items[j].Cells[(int)DataGridColumn.ROWNUM].Visible = false;
}
else
{
break;
}
}
rowNum = rowNum + ;
dg.Items[i].Cells[(int)DataGridColumn.ROWNUM].Text = System.Convert.ToString(rowNum);
i = j - ;
}
}
3.调用
SpanRow(dgDataGrid);
作者:Adolf Ye 出处:http://www.cnblogs.com/dt520/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |