zoukankan      html  css  js  c++  java
  • 分享两段行列合并算法

    使用一个将指定行列的gridview横向纵向合并行列,实现多复杂表头样式

    调用:

    GridCommon.Unitelist(this.grid1, 4);

    GridCommon.GroupCol(this.grid1, 4, dt.Columns.Count);

            /// <summary>
            /// 横向合并列
            /// </summary>
            public static void Unitelist(GridView gv, int rowIndex)
            {
                if (gv.Rows.Count < 1)
                {
                    return;
                }
                TableRow tr;
                for (int i = 0; i < rowIndex; i++)
                {
                    tr = gv.Rows[i];
                    if (gv.Rows[i].Cells.Count < 1)
                    {
                        return;
                    }
                    TableCell otcell = gv.Rows[i].Cells[0];
                    otcell.BackColor = System.Drawing.Color.FromArgb(219, 234, 253); //System.Drawing.Color.Teal;
                    otcell.HorizontalAlign = HorizontalAlign.Center;
                    for (int j = 1; j < gv.Rows[i].Cells.Count; j++)
                    {
                        TableCell tcell = gv.Rows[i].Cells[j];
                        if (tcell.Text == otcell.Text)
                        {
                            tcell.Visible = false;
                            if (otcell.ColumnSpan == 0)
                            {
                                otcell.ColumnSpan = 1;
                            }
                            otcell.ColumnSpan++;
                            otcell.VerticalAlign = VerticalAlign.Middle;
                            otcell.HorizontalAlign = HorizontalAlign.Center;
                            otcell.BackColor = System.Drawing.Color.FromArgb(219, 234, 253); //System.Drawing.Color.Teal;213, 237, 249
                            otcell.Wrap = false;
                        }
                        else
                        {
                            otcell = tcell;
                            otcell.HorizontalAlign = HorizontalAlign.Center;
                            otcell.BackColor = System.Drawing.Color.FromArgb(219, 234, 253);//System.Drawing.Color.Teal;
                        }
                    }
                }
            }
            /// <summary>
            /// 纵向合并列
            /// </summary>
            /// <param name="gv">GridView</param>
            /// <param name="colIndex">合并列的序号</param>
            public static void GroupCol(GridView gv, int rowIndex, int CellIndex)
            {
                if (gv.Rows.Count < 1)
                {
                    return;
                }
                TableRow tr;
                for (int j = 0; j < CellIndex; j++)
                {
                    TableRow oldTr = gv.Rows[0];
                    for (int i = 1; i < rowIndex; i++)
                    {
                        tr = gv.Rows[i];
                        if (oldTr.Cells[j].Text == tr.Cells[j].Text)
                        {
                            tr.Cells[j].Visible = false;
                            if (oldTr.Cells[j].RowSpan == 0)
                            {
                                oldTr.Cells[j].RowSpan = 1;
                            }
                            oldTr.Cells[j].RowSpan++;
                            oldTr.VerticalAlign = VerticalAlign.Middle;
                        }
                        else
                        {
                            oldTr = tr;
                        }
                    }
                }
            }
    

      

  • 相关阅读:
    [BZOJ2809][Apio2012]dispatching
    [BZOJ4584][Apio2016]赛艇
    [BZOJ3206][Apio2013]道路费用
    [codeforces551E]GukiZ and GukiZiana
    [BZOJ3809]Gty的二逼妹子序列
    [BZOJ3289]Mato的文件管理
    [BZOJ3052][UOJ#58][WC2013]糖果公园
    [SPOJ10707]Count on a tree II
    [BZOJ1086][SCOI2005]王室联邦
    python小知识
  • 原文地址:https://www.cnblogs.com/SharkLock-Chen/p/4713550.html
Copyright © 2011-2022 走看看