private void OnHandleAddSummaryField(object sender, CommandExecuteEventArgs e)
            {
                var designPanel = designMdiController.ActiveDesignPanel;
                var node        = (DataMemberListNodeBase)e.Args[0];

                var report        = designPanel.Report;
                var designerHost  = designPanel.GetService <IDesignerHost>();
                var changeServ    = designPanel.GetService <IComponentChangeService>();
                var selectionServ = designPanel.GetService <ISelectionService>();

                // Functionality patterned after AddCalculatedField() from DevExpress.XtraReports.Design.Commands.FieldListCommandExecutor, DevExpress.XtraReports.v16.1.Extensions.dll, Version=16.1.4.0
                var c = new SummaryField {
                    DataSource = node.DataSource != report.DataSource ? node.DataSource : null, DataMember = node.DataMember ?? string.Empty
                };
                var description = $"Add {nameof(SummaryField)} object";
                var transaction = designerHost.CreateTransaction(description);

                try
                {
                    var propertyDescriptor = XRAccessor.GetPropertyDescriptor(report, "CalculatedFields");
                    changeServ.OnComponentChanging(report, propertyDescriptor);
                    DesignToolHelper.AddToContainer(designerHost, c);
                    report.CalculatedFields.Add(c);
                    changeServ.OnComponentChanged(report, propertyDescriptor, null, null);
                }
                finally
                {
                    transaction.Commit();
                }
                selectionServ.SetSelectedComponents(new[] { c });
            }
예제 #2
0
            private void OnHandleAddSummaryField(object sender, CommandExecuteEventArgs e)
            {
                var designPanel      = designMdiController.ActiveDesignPanel;
                var fieldListControl = ((FieldListDockPanel)designDockManager[DesignDockPanelType.FieldList]).GetFieldList();
                var node             = fieldListControl.DataMemberNode;

                if (node == null)
                {
                    return;
                }
                if (!node.IsList)
                {
                    node = (DataMemberListNodeBase)node.ParentNode;
                }

                var report        = designPanel.Report;
                var designerHost  = designPanel.GetService <IDesignerHost>();
                var changeServ    = designPanel.GetService <IComponentChangeService>();
                var selectionServ = designPanel.GetService <ISelectionService>();

                // Functionality patterned after AddCalculatedField() from DevExpress.XtraReports.Design.Commands.FieldListCommandExecutor, DevExpress.XtraReports.v14.1.Extensions.dll, Version=14.1.5.0
                var c = new SummaryField {
                    DataSource = node.DataSource != report.DataSource ? node.DataSource : null, DataMember = node.DataMember ?? string.Empty
                };
                var description = string.Format("Add {0} object", typeof(SummaryField).Name);
                var transaction = designerHost.CreateTransaction(description);

                try
                {
                    var propertyDescriptor = XRAccessor.GetPropertyDescriptor(report, "CalculatedFields");
                    changeServ.OnComponentChanging(report, propertyDescriptor);
                    DesignToolHelper.AddToContainer(designerHost, c);
                    report.CalculatedFields.Add(c);
                    changeServ.OnComponentChanged(report, propertyDescriptor, null, null);
                }
                finally
                {
                    transaction.Commit();
                }
                selectionServ.SetSelectedComponents(new[] { c });
            }