Posted 19 September 2017, 10:51 am EST
Hi.
I am currently trying to implement merged column headers in WPF with the help of the Silverlight example found here: http://demo.componentone.com/silverlight/controlexplorer/#DataGrid/Headers%20Merging
My requirement is that only 2 columns are being mereged and the others should have no merging applied. And there lies my problem.
Lets assume I have 6 columns, the column 1, 2, 5, 6 are supposed to be “normal” columns.
Column 3, 4 are supposed to have merged headers.
After implementing the Silverlight example in my WPF application I get the following result:
Column 1, 2 are merged vertically and text is in the center.
Column 3, 4 have the first row merged horizontal and the 2nd row is unmerged.
Everything till now is like it should be, but now…
Column 5, 6 are unmerged neither horizontally, nor vertically so this column show up with doulbe text in there headers.
Hope the following helps to illustrate the problem:
Col 3 - Col 4 Col 5 Col 6
Col1 Col 2
Col 3 Col 4 Col 5 Col 6
Columns 5, 6 should also be merged vertically and the text aligned in center, so my desired result should be this:
Col 3 - Col 4
Col1 Col 2 Col 5 Col 6
Col 3 Col 4
The problem always occurs to columns that come after the merged columns, so if I would change the postion from columns 3, 4 to be at the very end all the previous columns would work like they should.
On the other side would I move them to the very front all following columns would be broken and unmerged.
After some digging around I may found the problem and want to share my finding with you, if its correct.
In the MergingHelper.cs from the Silverlight Example you will find the following code:
[csharp]
innerMerges = (orientation == Orientation.Vertical)
? Merge(orientation, range.Rows.ToArray(), pendingColumns, hierarchical)
: Merge(orientation, pendingRows, range.Columns.ToArray(), hierarchical);
[/csharp]
I modified it to this code:
[csharp]innerMerges = (orientation == Orientation.Vertical)
? Merge(Orientation.Horizontal, range.Rows.ToArray(), pendingColumns, hierarchical)
: Merge(Orientation.Vertical, pendingRows, range.Columns.ToArray(), hierarchical);[/csharp]
With this modification my problem is gone.
Will I face other problems with my modification or is it a “good” one?