zoukankan      html  css  js  c++  java
  • C# DataGrid合并单元格

    1.栏位枚举

      private enum DataGridColumn
        {
            ROWNUM = 0,
            EMPID,
            EMPNAME,
            SEX,
            SALARY,
            ADRRESS,
            PHONE,
            TEL,
            POSITIION,
            REMARK
        }


    2.合并函数

     private void SpanRow(DataGrid dg)
        {
            int i = 0;
            int j = 0;
            int rowNum = 0;//序号
            int rowSpan;
            string SEX = ""; //相同SEX,合并SEX单元格
            for (i = 0; i < dg.Items.Count; i++)
            {
                rowSpan = 1;
                SEX = dg.Items[i].Cells[(int)DataGridColumn.SEX].Text;
                for (j = i + 1; j < dg.Items.Count; j++)
                {
                    if (string.Compare(SEX, dg.Items[j].Cells[(int)DataGridColumn.SEX].Text) == 0)
                    {
                        rowSpan += 1;
                        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 + 1;
                dg.Items[i].Cells[(int)DataGridColumn.ROWNUM].Text = System.Convert.ToString(rowNum);
                i = j - 1;
            }
        }

     3.调用

      SpanRow(dgDataGrid);
    作者:Adolf Ye
    出处:http://www.cnblogs.com/dt520/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    springboot中MongoDB的使用
    SpringBoot中发送邮件服务
    springboot中使用RabbitMq
    PostgreSQL学习之【用户权限管理】说明
    Leet Code 19.删除链表的倒数第N个节点
    Kafka集群搭建
    Leet Code 18.四数之和
    Hadoop集群运行情况
    完全分布式Hadoop集群搭建
    Leet Code 17.电话号码的字母组合
  • 原文地址:https://www.cnblogs.com/dt520/p/5909583.html
Copyright © 2011-2022 走看看