Adding a Business Object as DataSource in designer

edited 9:46PM in FastReport .NET
How can I do it? Actually how is it done in "Business Objects.frx" report? As far as I can see there is no way to do it but still it is done in that report.

Comments

  • edited 9:46PM
    Hello,

    Here is how I do this in the demo:
          List<Category> list = new List<Category>();
          Category category = new Category("Beverages", "Soft drinks, coffees, teas, beers");
          category.Products.Add(new Product("Chai", 18m));
          category.Products.Add(new Product("Chang", 19m));
          category.Products.Add(new Product("Ipoh coffee", 46m));
          list.Add(category);
    
          category = new Category("Confections", "Desserts, candies, and sweet breads");
          category.Products.Add(new Product("Chocolade", 12.75m));
          category.Products.Add(new Product("Scottish Longbreads", 12.5m));
          category.Products.Add(new Product("Tarte au sucre", 49.3m));
          list.Add(category);
    
          category = new Category("Seafood", "Seaweed and fish");
          category.Products.Add(new Product("Boston Crab Meat", 18.4m));
          category.Products.Add(new Product("Red caviar", 15m));
          list.Add(category);
    
          FReport.Load(...);
          FReport.RegisterData(list, "Categories BusinessObject", BOConverterFlags.AllowFields, 3);
          FReport.Show();
    
    
    // business objects
        public class Category
        {
          public string Name;
          public string Description;
          public List<Product> Products;
    
          public Category(string name, string description)
          {
            Name = name;
            Description = description;
            Products = new List<Product>();
          }
        }
    
        public class Product
        {
          public string Name;
          public decimal UnitPrice;
    
          public Product(string name, decimal unitPrice)
          {
            Name = name;
            UnitPrice = unitPrice;
          }
        }
    
  • edited 9:46PM
    Thanks but this is in code. I want to know how can I do this in Designer.
    For example, when you open Business Objects.frx report in Designer and click Data -> Data Sources you can see the Business Objects DataSource. However if I want to add a DataSource i can only add DB data sources, not lists.
  • edited 9:46PM
    It can be done in Visual Studio IDE, "Data|Add New Data Source..." menu.
    - create new datasource which is bound to an object in your application;
    - add "BindingSource" component and connect it to your datasource;
    - put the "Report" component on your form, invoke its designer. You will be asked to choose a datasource. Select your BindingSource object.

    Note that in design-time, you cannot preview a report, because datasource is empty. This can be done in run-time only. In run-time, you should instantiate your datasource, fill it with data, then run a report.
  • edited 9:46PM
    OK, thanks. However I may get back to it later.
  • edited 9:46PM
    How can I do this in asp.net mvc project?
  • edited 9:46PM
    sv1r4 wrote: »
    How can I do this in asp.net mvc project?
    I have found solution by myself
    webReport.Report.Load(fileName);
    webReport.Report.Dictionary.RegisterBusinessObject(businessObjects, "BO", 10, true);
    webReport.Report.Save(fileName)
    
    And then I can open saved *.frx file in designer.
    Maybe someone can suggest better solution
  • edited 9:46PM
    AlexTZ wrote: »
    It can be done in Visual Studio IDE, "Data|Add New Data Source..." menu.
    - create new datasource which is bound to an object in your application;
    - add "BindingSource" component and connect it to your datasource;
    - put the "Report" component on your form, invoke its designer. You will be asked to choose a datasource. Select your BindingSource object.

    Note that in design-time, you cannot preview a report, because datasource is empty. This can be done in run-time only. In run-time, you should instantiate your datasource, fill it with data, then run a report.


    Hi,

    I am evaluating Fast Reports for .net.

    I have visual studio 2013. I am having trouble doing this step "add BindingSource component and connect it to your datasource;" can you make an example?

    Thanks.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.