Ticket T660257
Visible to All Users

XAF report not visible when no record on grid is selected. How to print all records from listview?

created 7 years ago (modified 7 years ago)

I created  inline report , but call report button action is visible only if i select one or many records on list view.
When i print report only selected records was printet. How can i print all records from list view without selecting all records (and print only selected if user select few records) ?

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

I find article that help me:
https://documentation.devexpress.com/eXpressAppFramework/113601/Task-Based-Help/Reporting/How-to-Print-a-Report-Without-Displaying-a-Preview

i prepared controller class:

C#
public abstract class PrintStacjeKlientowController : ObjectViewController<ListView, StacjeOMRKlientow> { private Klienci parent; public PrintStacjeKlientowController() { SimpleAction printAction = new SimpleAction(this, "PrintStacjeKlientow", PredefinedCategory.Reports); printAction.ImageName = "Action_Printing_Print"; printAction.Caption = "Print Station"; printAction.TargetViewNesting = Nesting.Nested; printAction.TargetViewType = ViewType.ListView; printAction.Execute += delegate (object sender, SimpleActionExecuteEventArgs e) { IObjectSpace objectSpace = ReportDataProvider.ReportObjectSpaceProvider.CreateObjectSpace(typeof(ReportDataV2)); IReportDataV2 reportData = objectSpace.FindObject<ReportDataV2>( new BinaryOperator("DisplayName", "Stacje OMR Klienta")); if (reportData == null) { throw new UserFriendlyException("Cannot find the 'Contacts Report' report."); } else { PrintReport(reportData, parent); } }; } protected override void OnActivated() { base.OnActivated(); View.CurrentObjectChanged += new EventHandler(View_CurrentObjectChanged); SetParentRecord(); } void View_CurrentObjectChanged(object sender, EventArgs e) { SetParentRecord(); } private void SetParentRecord() { NestedFrame nestedFrame = Frame as NestedFrame; if (nestedFrame != null) { if (((NestedFrame)Frame).ViewItem.CurrentObject is Klienci) { parent = ((NestedFrame)Frame).ViewItem.CurrentObject as Klienci; } } } protected override void OnDeactivated() { base.OnDeactivated(); void View_CurrentObjectChanged(object sender, EventArgs e) { View.CurrentObjectChanged -= new EventHandler(View_CurrentObjectChanged); } } protected abstract void PrintReport(IReportDataV2 reportData, Klienci parent); }

and in Win.Module

C#
public class WinPrintStacjeKlientowController : PrintStacjeKlientowController { protected override void PrintReport(IReportDataV2 reportData, Klienci parent) { XtraReport report = ReportDataProvider.ReportsStorage.LoadReport(reportData); ReportsModuleV2 reportsModule = ReportsModuleV2.FindReportsModule(Application.Modules); if (reportsModule != null && reportsModule.ReportsDataSourceHelper != null) { int customerNumber = parent.NUMERKLIENTA; CriteriaOperator co = new BinaryOperator("CustomerNumber", customerNumber.ToString()); reportsModule.ReportsDataSourceHelper.SetupBeforePrint(report, null, co, true, null, false); string FileName = "report.pdf"; report.ExportToPdf(FileName); Process.Start(FileName); } } }
    Comments (1)
    DevExpress Support Team 7 years ago

      Hello Debeściak,

      Thank you for sharing your solution. I am happy to hear that you have managed to solve this task using the example from our documentation.

      created 7 years ago (modified 7 years ago)

      Hello Debeściak,

      I found several tickets in our Support Center where we discussed a similar task. The following ticket has the most detailed answer: In-place report - How to print all records if user did not select one. Try the suggested solutions and let me know if they work for you.

      PS: I used the following keywords to search in Google: "xaf inplace report print all listview records". I If you already tried to search for our online learning materials using different keywords, please elaborate on the searches you made (key words in particular). With that, we can check if anything needs to be improved on our side (e.g., more key words need to be added). Such tuning can save a lot of development time for other customers in the future. Thanks for your collaboration in advance.

        Comments (3)
        JK JK
        Jacek Kosinski 7 years ago

          I try to use this but I have to run this functionality I Win modules
          and

          C#
          var reportServiceController = Frame.GetController<ReportServiceController>();

          returns null value

          if there is selected any record than nothing happens …

          C#
          public abstract class CustomPrintSelectionBaseController : PrintSelectionBaseController { public CustomPrintSelectionBaseController() : base() { ShowInReportAction.Execute += ShowInReportAction_Execute; } private void ShowInReportAction_Execute(object sender, DevExpress.ExpressApp.Actions.SingleChoiceActionExecuteEventArgs e) { if (e.SelectedObjects.Count == 0) { var reportServiceController = Frame.GetController<ReportServiceController>(); var reportData = (ReportDataInfo)e.SelectedChoiceActionItem.Data; reportServiceController.ShowPreview(reportData.ReportContainerHandle, GetCollectionSourceFilter() & GetGridFilter()); } } protected abstract CriteriaOperator GetGridFilter(); private CriteriaOperator GetCollectionSourceFilter() { var listView = (ListView)View; var collectionSource = listView.CollectionSource as CollectionSource; return collectionSource.GetTotalCriteria(); } }

          I modify controller for win module like here:

          C#
          namespace MailerX.Module.Win.Controllers { public class CustomPrintSelectionControllerWeb : CustomPrintSelectionBaseController { protected override CriteriaOperator GetGridFilter() { var listView = (ListView)View; var editor = (GridListEditor)listView.Editor; return CriteriaOperator.Parse(editor.Filter); } } }
          DevExpress Support Team 7 years ago

            Hello Debeściak,

            A ListView in a WinForms application always has at least one selected record. That is why, the built-in ShowInReport action will always display this record. The solution would be adding a custom ShowAllInReport action to the toolbar. Users will use it when it is necessary to export all records. Please let me know if this approach is acceptable in your scenario.

            JK JK
            Jacek Kosinski 7 years ago

              yes it is acceptable, but how to call this report in custom action - the code above doesn't work …

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.