# Region merge cells to merge all columns in a row
/// <Summary>
/// Merge rows with the same information in a row in the gridview (cell)
/// </Summary>
/// <Param name = "gridview1"> gridview object </param>
/// <Param name = "cellnum"> rows to be merged </param>
Public static void grouprow (gridview gridview1, int rows)
{
Tablecell oldtc = gridview1.rows [rows]. cells [0];
For (INT I = 1; I <gridview1.rows [rows]. cells. Count; I ++)
{
Tablecell Tc = gridview1.rows [rows]. cells [I]; // cells [0] is the column you want to merge
If (oldtc. Text = tc. text)
{
TC. Visible = false;
If (oldtc. columnspan = 0)
{
Oldtc. columnspan = 1;
}
Oldtc. columnspan ++;
Oldtc. verticalalign = verticalalign. Middle;
}
Else
{
Oldtc = tc;
}
}
}
# Endregion
# Region merge cells merge several columns in a row
/// <Summary>
/// Merge cells to merge several columns in a row
/// </Summary>
/// <Param name = "gridview1"> gridview id </param>
/// <Param name = "rows"> row </param>
/// <Param name = "Scol"> Start column </param>
/// <Param name = "Ecol"> end column </param>
Public static void grouprow (gridview gridview1, int rows, int Scol, int Ecol)
{
Tablecell oldtc = gridview1.rows [rows]. cells [Scol];
For (INT I = 1; I <Ecol-Scol; I ++)
{
Tablecell Tc = gridview1.rows [rows]. cells [I + Scol]; // cells [0] is the column you want to merge
TC. Visible = false;
If (oldtc. columnspan = 0)
{
Oldtc. columnspan = 1;
}
Oldtc. columnspan ++;
Oldtc. verticalalign = verticalalign. Middle;
}
}
# Endregion
# Region merge cells to merge all rows in a column
/// <Summary>
/// Merge rows with the same information in a column in the gridview (cell)
/// </Summary>
/// <Param name = "gridview1"> </param>
/// <Param name = "cellnum"> </param>
Public static void groupcol (gridview gridview1, int Cols)
{
If (gridview1.rows. Count <1 | Cols> gridview1.rows [0]. cells. Count-1)
{
Return;
}
Tablecell oldtc = gridview1.rows [0]. cells [Cols];
For (INT I = 1; I <gridview1.rows. Count; I ++)
{
Tablecell Tc = gridview1.rows [I]. cells [Cols];
If (oldtc. Text = tc. text)
{
TC. Visible = false;
If (oldtc. rowspan = 0)
{
Oldtc. rowspan = 1;
}
Oldtc. rowspan ++;
Oldtc. verticalalign = verticalalign. Middle;
}
Else
{
Oldtc = tc;
}
}
}
# Endregion
# Region merge cells to merge certain rows in a column
/// <Summary>
/// Merge cells to merge certain rows in a column
/// </Summary>
/// <Param name = "gridview1"> gridview id </param>
/// <Param name = "cellnum"> column </param>
/// <Param name = "srow"> Start row </param>
/// <Param name = "erow"> end column </param>
Public static void groupcol (gridview gridview1, int cols, int srow, int erow)
{
If (gridview1.rows. Count <1 | Cols> gridview1.columns. Count-1)
{
Return;
}
Tablecell oldtc = gridview1.rows [srow]. cells [Cols];
For (INT I = 1; I <erow-srow; I ++)
{
Tablecell Tc = gridview1.rows [srow + I]. cells [Cols];
TC. Visible = false;
If (oldtc. rowspan = 0)
{
Oldtc. rowspan = 1;
}
Oldtc. rowspan ++;
Oldtc. verticalalign = verticalalign. Middle;
}
}
# Endregion
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.