Hi,
I have a grid that I want to merge.
The merging needs to be by a column, but I don't want to display this column.
Is there a way to do this?
Thanks,Yael
Thanks a lot, this is exactly what I need! :)
Hi Yael,
Oh, okay, I get it now.
What you need is a MergedCellEvaluator on Column B that tells it to only merge the cells if both columns A and B are a match.
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { //// MERGED CELL FUNCTIONALITY RELATED ULTRAGRID SETTINGS //// ------------------------------------------------------------------------ // Set the merged cell style to the OnlyWhenSorted. e.Layout.Override.MergedCellStyle = MergedCellStyle.OnlyWhenSorted; e.Layout.Override.MergedCellContentArea = MergedCellContentArea.VisibleRect; e.Layout.Override.HeaderClickAction = HeaderClickAction.SortMulti; // ------------------------------------------------------------------------ e.Layout.Bands[0].SortedColumns.Add("A", false); e.Layout.Bands[0].SortedColumns.Add("B", false); e.Layout.Bands[0].SortedColumns.Add("C", false); e.Layout.Bands[0].Columns["A"].Hidden = true; e.Layout.Bands[0].Columns["B"].MergedCellEvaluator = new MyMergedCellEvaluator(); } public class MyMergedCellEvaluator : IMergedCellEvaluator { bool IMergedCellEvaluator.ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2, UltraGridColumn column) { string b1 = row1.GetCellText(column); string b2 = row1.GetCellText(column); string a1 = row1.GetCellText(column.Band.Columns["A"]); string a2 = row2.GetCellText(column.Band.Columns["A"]); return (string.Compare(b1, b2) == 0) && (string.Compare(a1, a2) == 0); } }
I will give an example:
I have 3 columns in the dataSource: A, B, C.
I wrote this:
void grdGrades_InitializeLayout(object sender, InitializeLayoutEventArgs e) { //// MERGED CELL FUNCTIONALITY RELATED ULTRAGRID SETTINGS //// ------------------------------------------------------------------------ // Set the merged cell style to the OnlyWhenSorted. e.Layout.Override.MergedCellStyle = MergedCellStyle.OnlyWhenSorted; e.Layout.Override.MergedCellContentArea = MergedCellContentArea.VisibleRect; e.Layout.Override.HeaderClickAction = HeaderClickAction.SortMulti; // ------------------------------------------------------------------------
e.Layout.Bands[0].SortedColumns.Add("A", false); e.Layout.Bands[0].SortedColumns.Add("B", false); e.Layout.Bands[0].SortedColumns.Add("C", false); }
So if I have this data:
row 1: aaa, bbb, ccc
row 2: aaa, bbb, c
row 3: a, bbb, cc
In the grid, it will be displayed like this:
C
B
A
ccc
bbb
aaa
c
cc
a
I don't want to display column A, but I still want that columns B and C will be affected by it.
so I want that even when column A is hidden, the grid will look like this:
Please help me to find a solution.
I don't understand what you mean. What does it mean to merge a column that is not visible?