How to merge cells in a gridview

Source: Internet
Author: User

/// <Summary> <br/> // merge cells <br/> /// </Summary> <br/> /// <Param name = "gridview"> form for merging cells </param> <br/> // <Param name = "arryjudgecell"> column to be determined </param> <br/> // <param name = "arrycellnum"> columns to be merged </param> <br/> Public static void dounitegrouprowsgrid (gridview, int [] arryjudgecell, int [] arrycellnum) <br/>{< br/> int I = 0, rowspannum = 1; <br/> bool flagsame = true; <br/> while (I <gridvie W. rows. count-1) <br/>{< br/> // obtain the current row <br/> gridviewrow gvrthis = gridview. rows [I]; <br/> for (++ I; I <gridview. rows. count; I ++) <br/>{< br/> gridviewrow gvrnext = gridview. rows [I]; <br/> for (Int J = 0; j <arryjudgecell. length; j ++) <br/>{< br/> flagsame = true; <br/> If (gvrthis. cells [arryjudgecell [J]. text! = Gvrnext. cells [arryjudgecell [J]. text) <br/>{< br/> flagsame = false; <br/> break; <br/>}< br/> If (flagsame) <br/> {<br/> for (int K = 0; k <arrycellnum. length; k ++) <br/>{< br/> gvrnext. cells [arrycellnum [k]. visible = false; <br/>}< br/> rowspannum ++; <br/>}< br/> else <br/> {<br/> for (int K = 0; k <arrycellnum. length; k ++) <br/>{< br/> gvrthis. cells [arrycellnum [k]. rowspan = rowspannum; <br/>}< br/> rowspannum = 1; <br/> break; <br/>}< br/> if (I = gridview. rows. count-1) <br/>{< br/> for (int K = 0; k <arrycellnum. length; k ++) <br/>{< br/> gvrthis. cells [arrycellnum [k]. rowspan = rowspannum; <br/>}< br/>}# Region merge cells to merge certain rows in a column <br/> /// <summary> <br/> // merge cells to merge certain rows in a column <br/> /// </Summary> <br/> /// <Param name = "gridview1"> gridview id </param> <br/> // <Param name = "cellnum"> column </param> <br/> // <Param name = "srow"> Start row </param> <br/> // <Param name = "erow"> end column </param> <br/> Public static void groupcol (gridview gridview1, int cols, int srow, int erow) <br/>{< br/> If (gridview1.rows. count <1 | Cols> gridview1.columns. count-1) <br/>{< br/> return; <br/>}< br/> tablecell oldtc = gridview1.rows [srow]. cells [Cols]; <br/> for (INT I = 1; I <erow-srow; I ++) <br/>{< br/> tablecell Tc = gridview1.rows [srow + I]. cells [Cols]; <br/> TC. visible = false; <br/> If (oldtc. rowspan = 0) <br/>{< br/> oldtc. rowspan = 1; <br/>}< br/> oldtc. rowspan ++; <br/> oldtc. verticalalign = verticalalign. middle; <br/>}< br/> # endregion 

# Region merge cells to merge all columns of a row <br/> /// <summary> <br/> // merge rows with the same information in a row in the gridview (cell) <br/> /// </Summary> <br/> // <Param name = "gridview1"> gridview object </param> <br/> // <param name = "cellnum"> rows to be merged </param> <br/> Public static void grouprow (gridview gridview1, int rows) <br/>{< br/> tablecell oldtc = gridview1.rows [rows]. cells [0]; <br/> for (INT I = 1; I <gridview1.rows [rows]. cells. count; I ++) <br/>{< br/> tablecell Tc = gridview1.rows [rows]. cells [I]; // cells [0] is the column you want to merge <br/> If (oldtc. TEXT = tc. text) <br/>{< br/> TC. visible = false; <br/> If (oldtc. columnspan = 0) <br/>{< br/> oldtc. columnspan = 1; <br/>}< br/> oldtc. columnspan ++; <br/> oldtc. verticalalign = verticalalign. middle; <br/>}< br/> else <br/> {<br/> oldtc = tc; <br/>}< br/> # endregion 

# Region merge several columns in a row of cells <br/> /// <summary> <br/> // merge several columns in a row of cells <br/> /// </Summary> <br/> /// <Param name = "gridview1"> gridview id </param> <br/> /// <Param name = "rows"> row </param> <br/> /// <Param name = "Scol"> Start column </param> <br/> /// <Param name = "Ecol"> end column </param> <br/> Public static void grouprow (gridview gridview1, int rows, int Scol, int Ecol) <br/>{< br/> tablecell oldtc = gridview1.rows [rows]. cells [Scol]; <br/> for (INT I = 1; I <Ecol-Scol; I ++) <br/>{< br/> tablecell Tc = gridview1.rows [rows]. cells [I + Scol]; // cells [0] is the column you want to merge <br/> TC. visible = false; <br/> If (oldtc. columnspan = 0) <br/>{< br/> oldtc. columnspan = 1; <br/>}< br/> oldtc. columnspan ++; <br/> oldtc. verticalalign = verticalalign. middle; <br/>}< br/> # endregion 

<Br/> # merge region cells to merge all rows in a column <br/> /// <summary> <br/> // merge rows with the same information in a column in the gridview (cell) <br/> /// </Summary> <br/> // <Param name = "gridview1"> </param> <br/> // <Param name = "cellnum"> </param> <br/> Public static void groupcol (gridview gridview1, int Cols) <br/>{< br/> If (gridview1.rows. count <1 | Cols> gridview1.rows [0]. cells. count-1) <br/>{< br/> return; <br/>}< br/> tablecell oldtc = gridview1.rows [0]. cells [Cols]; <br/> for (INT I = 1; I <gridview1.rows. count; I ++) <br/>{< br/> tablecell Tc = gridview1.rows [I]. cells [Cols]; <br/> If (oldtc. TEXT = tc. text) <br/>{< br/> TC. visible = false; <br/> If (oldtc. rowspan = 0) <br/>{< br/> oldtc. rowspan = 1; <br/>}< br/> oldtc. rowspan ++; <br/> oldtc. verticalalign = verticalalign. middle; <br/>}< br/> else <br/> {<br/> oldtc = tc; <br/>}< br/> # endregion 

 

This article from: http://www.itwis.com/html/net/net20/20080919/2443_2.html

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.