Gridview merge cells with multiple rows and columns (specify column merging)

Source: Internet
Author: User

Last week I wrote an article about how to merge multiple rows and columns of cells (complete code and examples) IN THE gridview. There are many shortcomings in the implementation method. For example, you can only merge consecutive columns, but not template columns. In today'sArticleFirst, solve the first problem.

It is not difficult to solve this problem.CodeThe merging of consecutive columns has been solved. to merge the specified columns, you only need to pass the columns to be merged to the merging method in order! The code for merging specified columns is as follows:

 
1:/// <Summary>
 
2:/// Merge the gridview Cells
 
3:/// </Summary>
 
4:/// <Param name = "GV"> the gridview to be merged </param>
 
5:/// <Param name = "Cols"> specify columns, which must be passed in order </param>
6:Public Static VoidMergerow (gridview GV,Params Int[] Cols)
 
7:{
 
8:Rowarg init =NewRowarg ()
 
9:{
 
10:Startrowindex = 0,
 
11:Endrowindex = GV. Rows. Count-2
 
12:};
 
13:For(IntI = 0; I <cols. length; I ++)
 
14:{
15:If(I> 0)
 
16:{
 
17:List <rowarg> List =NewList <rowarg> ();
 
18:// Traverse the previous column from the second column
 
19:Traversesprevcol (GV, cols [I-1], list );
 
20:Foreach(VAR itemInList)
 
21:{
 
22:Mergerow (GV, cols [I], item. startrowindex, item. endrowindex );
23:}
 
24:}
 
25:// Merge the rows in the Start Column
 
26:Else
 
27:{
 
28:Mergerow (GV, I, init. startrowindex, init. endrowindex );
 
29:}
 
30:}
 
31:}

At the end of the previous article, I wrote a simple example. In this example, as shown in (left), the first four columns are merged, and the first column is Michael, the second column is Michael's salary item: pay-as-you-go and five insurances and one gold. The third column is the sub-item of pay-as-you-go: basic salary, bonus and overtime, and the sub-item of five insurances and one gold: medical insurance and housing provident fund. Column 4 Basic Salary: January, bonus: January, overtime: January... Normally, the fourth column is in December January and should all be merged into one piece. To solve this problem, you can adjust the column sequence by using the continuous column merge method. However, if you cannot adjust the column sequence, you can only merge the columns as specified.

After the intermediate merge format is completed, you only need to call the method at the beginning of this article after the gridview is bound to the data, and input the column sequence, to complete the merge format of the right graph, you only need to input the order of the columns 0, 3, 1, 2.

 
1:// Left chart
 
2:Mergegridviewcell. mergerow (gridview1, 0, 3 );
 
3:// Intermediate Diagram
 
4:Mergegridviewcell. mergerow (gridview1, 0, 1, 3, 2 );
 
5:// Right image
 
6:Mergegridviewcell. mergerow (gridview1, 0, 3, 1, 2 );

Finally explain, this article is completed on the basis of the previous article, if you are interested in this, you can first read the previous article, and finally attach the source code of this article: http://pan.baidu.com/share/link? Consumer id = 87931 & UK = 2466437167

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.