Category / Section
How to work around a defect in the older version of the elements in Table Collection?
2 mins read
Iterate element
Problem
A defect in the Grouping.ElementsInTableCollection enumerator is detected and fixed in the version post 4.1.0.62. While iterating through the Table.Elements in the groupingEngine that has a hierarchical DataSource, and when the last child element in a parent record is reached, it moves on to the sibling elements of the subsequent child table elements instead of moving to the next element in the top level.
Solution
When using the older version, this can be worked around by getting the enumerator. You also have to iterate the elements in the ElementsInTableCollection by using the for loop, skipping the repeated nested table elements.
C#
private void ShowWorkAround(TreeNode node,IList arrElements) { // ***Workarounds when you are not using the version post 4.1.0.62 // ***Includes a fix for enumerator issue int count = arrElements.Count; IEnumerator enumer = arrElements.GetEnumerator(); System.Diagnostics.Trace.WriteLine(arrElements.Count.ToString()); bool flag= enumer.MoveNext(); for(int i = 0; i < count && flag; i++) { Element element = enumer.Current as Element; if(element.Kind == DisplayElementKind.NestedTable) { --i; flag = enumer.MoveNext(); continue; } else flag = enumer.MoveNext(); // ***end of workaround for Enumerator problem. if(element.Kind == DisplayElementKind.Record) { Record rec = Element.GetRecord(element); // Printouts the record. System.Diagnostics.Trace.WriteLine(rec.ToString()); node.Nodes.Add(rec.ToString()); // Checks if it has nestedTables. if(rec.NestedTables.Count > 0) { // Printouts elements in it node = node.LastNode; foreach(GridNestedTable gnt in rec.NestedTables) { System.Diagnostics.Trace.Indent(); ShowWorkAround(node,gnt.ChildTable.Elements); System.Diagnostics.Trace.Unindent(); } node = node.Parent; } } else { // Prints (Captions, AddNew records, etc. *** SKIP if element is NestedTable***) if(element.Kind != DisplayElementKind.NestedTable) { System.Diagnostics.Trace.WriteLine(element); node.Nodes.Add(element.ToString()); } } } }
VB
Private Sub ShowWorkAround(ByVal node As TreeNode, ByVal arrElements As IList) ' ***Workarounds when you are not using the version post 4.1.0.62 ' *** Includes a fix for enumerator issue Dim count As Integer = arrElements.Count Dim enumer As IEnumerator = arrElements.GetEnumerator() System.Diagnostics.Trace.WriteLine(arrElements.Count.ToString()) Dim flag As Boolean= enumer.MoveNext() Dim i As Integer = 0 Do While i < count AndAlso flag Dim element As Element = TryCast(enumer.Current, Element) If element.Kind = DisplayElementKind.NestedTable Then i -= 1 flag = enumer.MoveNext() i += 1 Continue Do Else flag = enumer.MoveNext() End If ' ***end of workaround for Enumerator problem. If element.Kind Is DisplayElementKind.Record Then Dim rec As Record = Element.GetRecord(element) ‘Printouts the record. System.Diagnostics.Trace.WriteLine(rec.ToString()) node.Nodes.Add(rec.ToString()) ‘Checks if it has nested Tables.. If rec.NestedTables.Count > 0 Then ' Printouts elements in it node = node.LastNode For Each gnt As GridNestedTable In rec.NestedTables System.Diagnostics.Trace.Indent() ShowWorkAround(node,gnt.ChildTable.Elements) System.Diagnostics.Trace.Unindent() Next gnt node = node.Parent End If Else ' Prints (Captions, AddNew records, etc *** SKIP if element is NestedTable***) If element.Kind <> DisplayElementKind.NestedTable Then System.Diagnostics.Trace.WriteLine(element) node.Nodes.Add(element.ToString()) End If End If i += 1 Loop End Sub
Samples: