private void ProcessResultRows(
            AnalysisResult result,
            UPMGridPage searchPage,
            IReadOnlyList <object> xColumnArray,
            bool keyAsRawString,
            int columnCount,
            UPMResultSection section)
        {
            var i          = 0;
            var resultRows = CreateResultRows(result);
            var sumRow     = result.SumLine;

            foreach (AnalysisRow row in resultRows)
            {
                var identifier = StringIdentifier.IdentifierWithStringId($"row {i}");
                var listRow    = new UPMResultRow(identifier)
                {
                    Context = row
                };
                i++;
                var fieldArray = CreateFieldArray(row, xColumnArray, keyAsRawString, columnCount, i);

                listRow.Fields = fieldArray;
                if (searchPage.FixedSumRow && sumRow != null && i == resultRows.Count && resultRows.Count > 12)
                {
                    searchPage.SumResultRow = listRow;
                    searchPage.SumRowAtEnd  = false;
                }
                else
                {
                    section.AddResultRow(listRow);
                }

                if (row.HasDetails)
                {
                    var detailGroupCol1 = new UPMAnalysisResultRowGroup(StringIdentifier.IdentifierWithStringId("det1"))
                    {
                        Invalid = true,
                        Left    = true,
                        Row     = row
                    };
                    listRow.AddDetailGroup(detailGroupCol1);
                    var detailGroupCol2 = new UPMAnalysisResultRowGroup(StringIdentifier.IdentifierWithStringId("det2"))
                    {
                        Invalid = true,
                        Left    = false,
                        Row     = row
                    };
                    listRow.AddDetailGroup(detailGroupCol2);
                }

                this.AddDrilldownActionsFromRowToListRow(row, listRow);
                this.AddDetailsActionFromRowToListRow(row, listRow);
            }
        }
        private static UPMElement UpdatedElementForResultRowGroup(UPMAnalysisResultRowGroup rowGroup)
        {
            var group = new UPMAnalysisResultRowGroup(rowGroup.Identifier)
            {
                Left = rowGroup.Left,
                Row  = rowGroup.Row
            };

            var rowDetails = rowGroup.Row.RowDetails;

            if (rowGroup.Left)
            {
                bool firstXCategory = true;
                foreach (AnalysisResultCell resultCell in rowGroup.Row.Values)
                {
                    var field = new UPMStringField(null)
                    {
                        LabelText   = resultCell.Column.Label,
                        StringValue = resultCell.StringValue
                    };

                    group.AddField(field);
                    int xCount = resultCell.XResultCells.Count;
                    if (firstXCategory && xCount > 0)
                    {
                        int i;
                        firstXCategory = false;
                        for (i = 0; i < xCount; i++)
                        {
                            field = new UPMStringField(null)
                            {
                                LabelText   = $"X:{resultCell.Column.XCategoryValues[i].Label}",
                                StringValue = resultCell.XResultCells[i].StringValue
                            };

                            group.AddField(field);
                        }
                    }
                }
            }
            else
            {
                int maxCount = 0;
                foreach (AnalysisRowDetails rowDet in rowDetails)
                {
                    var            stringValues = rowDet.StringValues;
                    int            count        = stringValues.Count;
                    UPMStringField field        = null;
                    if (stringValues.Count > 0)
                    {
                        field = new UPMStringField(null);
                        if (++maxCount > 3)
                        {
                            field.LabelText   = "Number of Results:";
                            field.StringValue = $"{rowDetails.Count}";
                            group.AddField(field);
                            break;
                        }

                        if (count > 1)
                        {
                            field.LabelText   = stringValues[0];
                            field.StringValue = stringValues[1];
                        }
                        else
                        {
                            field.StringValue = stringValues[0];
                        }
                    }

                    if (field != null)
                    {
                        group.AddField(field);
                    }
                }
            }

            return(group);
        }