zoukankan      html  css  js  c++  java
  • 车辆信息统计报表管理系统GridView和DataGridView合并行和列

      源代码:

            ///<summary>

            /// Web合并相同数据的行标题

            ///</summary>

            ///<param name="gv"></param>

            ///<param name="col"></param>

            ///<param name="colName"></param>

            public static void Unite(GridView gv, int[] col, string[] colName)

            {

                int i;

                string LastType1;//主键第一列字段名

                string LastType2;

                int LastCell;

                if (gv.Rows.Count > 0)

                {

                    for (int j = 0; j < col.Length; j++)

                    {

                        LastType1 = gv.Rows[0].Cells[int.Parse(colName[0].ToString())].Text;

                        LastType2 = gv.Rows[0].Cells[int.Parse(colName[j].ToString())].Text;

                        gv.Rows[0].Cells[col[j]].RowSpan = 1;

                        LastCell = 0;

                        for (i = 1; i < gv.Rows.Count; i++)

                        {

                            if (gv.Rows[i].Cells[int.Parse(colName[j].ToString())].Text == LastType2 && gv.Rows[i].Cells[int.Parse(colName[0].ToString())].Text == LastType1)

                            {

                                gv.Rows[i].Cells[col[j]].Visible = false;

                                gv.Rows[LastCell].Cells[col[j]].RowSpan++;

                            }

                            else

                            {

                                LastType1 = gv.Rows[i].Cells[int.Parse(colName[0].ToString())].Text;

                                LastType2 = gv.Rows[i].Cells[int.Parse(colName[j].ToString())].Text;

                                LastCell = i;

                                gv.Rows[i].Cells[col[j]].RowSpan = 1;

                            }

                        }

                    }

                }

            }

     

            ///<summary>

            /// Web设置指定行合并列

            ///</summary>

            ///<param name="gv"></param>

            ///<param name="pRowIndex">要合并列的行号</param>

            public static void UniteColumn(GridView gv, int pRowIndex,int pColIndex,int pSpanCount)

            {

                gv.Rows[pRowIndex].Cells[pColIndex].ColumnSpan = pSpanCount;

              

                for (int i = 1; i < pSpanCount; i++)

                {

                    gv.Rows[pRowIndex].Cells[pColIndex + i].Visible = false;

                }

                gv.Rows[pRowIndex].Cells[pColIndex].Width = Unit.Pixel(0);

               

            }

     

            ///<summary>

            /// Winform合并相同数据的行标题

            ///</summary>

            ///<param name="gv"></param>

            ///<param name="col"></param>

            ///<param name="colName"></param>

            public static void Unite(DataGridView gv, int[] col, string[] colName)

            {

                int i;

                string LastType1;//主键第一列字段名

                string LastType2;

                int LastCell;

                if (gv.Rows.Count > 0)

                {

                    for (int j = 0; j < col.Length; j++)

                    {

                        LastType1 = gv.Rows[0].Cells[int.Parse(colName[0].ToString())].Value.ToString();

                        LastType2 = gv.Rows[0].Cells[int.Parse(colName[j].ToString())].Value.ToString();

                        ((gv.Rows[0].Cells[col[j]]) as  DataGridViewTextBoxCellEx).RowSpan = 1;

                        LastCell = 0;

                        for (i = 1; i < gv.Rows.Count; i++)

                        {

                            if (gv.Rows[i].Cells[int.Parse(colName[j].ToString())].Value.ToString() == LastType2 && gv.Rows[i].Cells[int.Parse(colName[0].ToString())].Value.ToString() == LastType1)

                            {

                                //gv.Rows[i].Cells[col[j]].Visible = false;

                                (gv.Rows[LastCell].Cells[col[j]] as DataGridViewTextBoxCellEx).RowSpan++;

                            }

                            else

                            {

                                LastType1 = gv.Rows[i].Cells[int.Parse(colName[0].ToString())].Value.ToString();

                                LastType2 = gv.Rows[i].Cells[int.Parse(colName[j].ToString())].Value.ToString();

                                LastCell = i;

                                 (gv.Rows[i].Cells[col[j]] as DataGridViewTextBoxCellEx).RowSpan = 1;

                            }

                        }

                    }

                }

            }

          ///<summary>

            /// DataGridView设置指定行合并列

          ///</summary>

          ///<param name="pDataGridView"></param>

            ///<param name="pRowIndex">要合并列的行号</param>

            ///<param name="pColumnIndex">起始列索引数</param>

            ///<param name="pColumnNumber">合并列数量</param>

            ///<param name="pBackColor">背景色彩</param>

            public static void SetColumnMerge(DataGridView pDataGridView, int pRowIndex, int pColumnIndex, int pColumnNumber, Color pBackColor)

            {

                var cell = (DataGridViewTextBoxCellEx)pDataGridView[pColumnIndex, pRowIndex];

                cell.ColumnSpan = pColumnNumber;

                cell.RowSpan = 1;

                cell.Style.BackColor = pBackColor;

            }

     

    调用:

                                                           UnitGVTitle.UniteColumn(gv, rowCount, 0, 3);

                                UnitGVTitle.UniteColumn(gv, rowCount, 3, 1);

                                UnitGVTitle.UniteColumn(gv, rowCount, 4, 3);

     

    效果:

    查看更多精彩图片

    下载

    DataGridViewTextBoxCellEx.cs

  • 相关阅读:
    Digital Video Stabilization and Rolling Shutter Correction using Gyroscope 论文笔记
    Distortion-Free Wide-Angle Portraits on Camera Phones 论文笔记
    Panorama Stitching on Mobile
    Natural Image Stitching with the Global Similarity Prior 论文笔记 (三)
    Natural Image Stitching with the Global Similarity Prior 论文笔记(二)
    Natural Image Stitching with the Global Similarity Prior 论文笔记(一)
    ADCensus Stereo Matching 笔记
    Efficient Large-Scale Stereo Matching论文解析
    Setting up caffe on Ubuntu
    Kubernetes配置Secret访问Harbor私有镜像仓库
  • 原文地址:https://www.cnblogs.com/Gemgin/p/3136359.html
Copyright © 2011-2022 走看看