在DataGrid中合并单元格行
最近在做项目的时候经常遇到要合并单元格的情况,发现这个东西.net中并没有现成的方法,研究了一下,总结了两种方法。
这个主要都是行合并的,有以下两种情况
1、多行合并为一行,其中将某个或某几个单元格的内容合并起来
原始样式:
column1 column2
1 a
1 b
1 c
1 d
2 q
2 w
2 e
需要效果:
column1 column2
1 a\b\c\d
2 q\w\e
代 码:
![](https://rickel.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
2、将Datagrid中的某些相同的单元格合并
原始样式:
Column1 Column2
1 a
1 b
1 c
2 x
2 y
2 z
需要效果:
Column1 Column2
a
1 b
c
_____________________________
x
2 y
z
代 码:
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://rickel.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
以上两种方法可合并使用