- #region 合并成为矩形单元格
- /// <summary>
- /// 合并成为矩形单元格
- /// </summary>
- /// <param name="GridView1"></param>
- /// <param name="sRow">开始行索引</param>
- /// <param name="sCol">开始列索引</param>
- /// <param name="eRow">结束行索引</param>
- /// <param name="eCol">结束列索引</param>
- public static void GroupRectangle(GridView GridView1, int sRow, int sCol, int eRow, int eCol)
- {
- if (sRow < 0 || sRow > eRow || eRow > GridView1.Rows.Count - 1)
- {
- return;
- }
- if (sCol < 0 || sCol > eCol || eCol > GridView1.Columns.Count - 1)
- {
- return;
- }
- TableCell oldTc = GridView1.Rows[sRow].Cells[sCol];
- oldTc.ColumnSpan = eCol - sCol + 1;
- oldTc.RowSpan = eRow - sRow + 1;
- //oldTc.ColumnSpan = eCol - sCol > 0 ? eCol - sCol : 1;
- //oldTc.RowSpan = eRow - sRow > 0 ? eRow - sRow : 1;
- for (int i = sRow; i <= eRow; i++)
- {
- for (int j = sCol; j <= eCol; j++)
- {
- if (i == sRow && j == sCol)//起始单元格
- {
- //oldTc.ColumnSpan = 1;
- //oldTc.RowSpan = 1;
- continue;
- }
-
- TableCell tc = GridView1.Rows[i].Cells[j];
- tc.Visible = false;
- }
- }
- oldTc.Visible = true;
- oldTc.VerticalAlign = VerticalAlign.Middle;
- oldTc.HorizontalAlign = HorizontalAlign.Center;
- }
- #endregion
复制代码
|
|