Not able to generate dynamic columns in sub report with data repeating in group

Posted by: shelza.gupta on 5 November 2019, 3:36 am EST

    • Post Options:
    • Link

    Posted 5 November 2019, 3:36 am EST - Updated 30 September 2022, 8:28 am EST

    Hi All,

    I want to generate a report that groups data on the basis of a key and has a subreport. But I want to add dynamic columns in subreport as per requirements for that particular key. I am able to achieve the same when I have a single key but not with multiple keys.

    I have attached two images. One is my requirement(data is dynamic) and the other one is the error message I received while implementing the same.

    Regards,

    Shelza

  • Posted 5 November 2019, 8:26 pm EST

    Hello Shelza,

    As per my understanding, you wish to have a report layout where a group exists and the subreport is added to the Detail section of the report such that it picks up columns based on the DataField set for the group. Please confirm.

    Also, I would need your stripped down application or the code snippet to see what exactly causes the issue and how can the same be resolved.

    Regards,

    Esha

  • Posted 5 November 2019, 10:01 pm EST

    Hello Esha,

    I have some static fields in subreport. On the conditional basis, I am trying to add dynamic controls in subreport. I am able to achieve it for single dataset, but when I am trying it with multiple datasets, I am getting the error. Hope this would help otherwise I’ll share sample code with you.

    Regards,

    Shelza

  • Posted 6 November 2019, 10:45 pm EST

    Hi Shelza,

    Unfortunately, the provided information still does not help us comprehend the exact layout of the report and the requirement. It would be helpful if you share the sample code. This will help us provide you timely assistance.

    Thanks,

    Esha

  • Posted 11 November 2019, 4:27 pm EST

    Hi Esha,

    PFA, the sample code. Kindly help.

    Thanks,

    Shelza

    SampleGrapeCity.zip

  • Posted 12 November 2019, 10:38 pm EST

    Hello Shelza,

    Please create the instance of SectionRpt in “groupHeader1_Format” event instead of “MainRpt_ReportStart” like as follow:

    
      private void groupHeader1_Format(object sender, EventArgs e)
            {
                   sectionReport = new SectionRpt();
                   string filter = "RollNo = '" + this.Fields["RollNo"].Value.ToString() + "'";
                DataTable dtv = dt.Select(filter, "").CopyToDataTable();
                subReport1.Visible = false;
                subReport1.Report = sectionReport;
                if (dtv.Rows.Count > 0)
                {
                    //Adding column dynamically
                    if (dtv.Rows[0]["RollNo"].ToString() == "2")
                    {
                        dtv.Columns.Add("Sub3");
                        dtv.Rows[0]["Sub3"] = "Computers";
                    }
                    sectionReport.DataSource = dtv;
                    subReport1.Visible = true;
                }
            }
            private void MainRpt_ReportStart(object sender, EventArgs e)
            {
                label1.DataField = "StName";
              
                dt.Columns.Add("RollNo");
                dt.Columns.Add("StName");
                dt.Columns.Add("Grade");
                dt.Columns.Add("Sub1");
                dt.Columns.Add("Sub2");
                dt.Rows.Add(1, "TestStudent1", "1", "Maths", "Science");
                dt.Rows.Add(2, "TestStudent2", "2", "Drawing", "Science");
                dt.Rows.Add(3, "TestStudent3", "3", "Maths", "Computers");
                DataSource = dt;
                groupHeader1.DataField = "RollNo";
    
            }
    
    

    Thanks,

  • Posted 12 November 2019, 10:39 pm EST

    Also, Sorry to mention that AR7 was declared a legacy product now. It is out of maintenance mode now. Hence, we do not provide support for the same or no bug fixing will be done in the same. I would recommend you use the latest version of ActiveReports i.e ActiveReports 13. Please refer to the following link for more information:

    https://www.grapecity.com/activereports.

  • Posted 13 November 2019, 3:53 pm EST

    Thank you Mohit for the solution.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels