Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:06:47+00:00 2026-05-31T01:06:47+00:00

I don’t know if the follow code snippet intend to work in this way,

  • 0

I don’t know if the follow code snippet intend to work in this way, because sometimes we “as developers” try automate creation of data display control where number of fields are uncontrolled and with similar data-binding, so before I review the application some guys left this :

Under ActiveReport_ReportStart() event :

    for (Ind = 1; Ind <=CM.Length; Ind++) {

        if (Ind == 1) {
            Left = ((Line)rpt.Sections["PageHeader"].Controls["lnH8"]).Left + 0.05f;
        } else if (Ind == 2) {
            Left = ((Line)rpt.Sections["PageHeader"].Controls["lnH9"]).Left + 0.05f;
        } else if (Ind == 3) {
            Left = ((Line)rpt.Sections["PageHeader"].Controls["lnH10"]).Left + 0.05f;
        }

        TextBox TB = new TextBox();
        TB.Size = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Size;
        TB.Font = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Font;
        TB.Width = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Width;
        TB.Height = ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Height;
        TB.VerticalAlignment = VerticalTextAlignment.Top;
        TB.Location =  new System.Drawing.PointF(Left, ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Top);
        TB.DataField = "ColorText" + Ind + ColorwayNumber;
        rpt.Sections["Detail"].Controls.Add(TB);

It doesn’t have compilation error when is previewed, also others fields that are not auto-generated are displayed correctly (ReporHeader, ReportFooter), but IMHO I think is better to replace this mechanism by a subreport inside the detail section, of course these fields have to be displayed in Detail section of the report. Anyways I would like to see some recommendations because if is possible to auto-generated textbox or labels in runtime I will have to explain to boss why this code was not working, and if I have to use subreports instead, I need to know how to pass parameter (at least I need to work with two parameters for generate another sql query for it) and what “event” is proper to put script into it..


After I discovered that most important problem is to get report format changes by how many field/textbox were added to report detail in runtime restricted by a sqlquery return value, for example :

  1. Returned SQLQuery value = 4
  2. 10 fields generated for detailed row 1
  3. 6 fields for row 2
  4. 4 fields for row 3

Detail fields are bound to a SQL Store Procedure*

Report will supossed to be printed/showed in this way :

//Report Init
    
    Page 1 :
                         |field 1|field 2|field 3|field 4|
    ------------------------------------------------------
    row1                 | valA1 | valA2 | valA3 | valA4 |
    ------------------------------------------------------
    row2                 | valB1 | valB2 | valB3 | valB4 |
    ------------------------------------------------------
    row3                 | valC1 | valC2 | valC3 | valC4 |
    ------------------------------------------------------

    Page 2 :
                         |field 1|field 2|field 3|field 4|
    ------------------------------------------------------
    row1                 | valA5 | valA6 | valA7 | valA8 |
    ------------------------------------------------------
    row2                 | valB5 | valB6 |
    ------------------------------------------------------
    row3                 
    ------------------------------------------------------

    Page 3 :
                         |field 1|field 2|field 3|field 4|
    ------------------------------------------------------
    row1                 | valA9 | valA10| 
    ------------------------------------------------------
    row2                 
    ------------------------------------------------------
    row3                 
    ------------------------------------------------------
//End of Report

Any help will be appreciated

Thank you so much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:06:49+00:00Added an answer on May 31, 2026 at 1:06 am

    It is perfectly fine to dynamically create fields on a report at runtime. The creation of those fields do indeed need to be done in the reportstart event or earlier (i.e. before calling ActiveReport.Run).

    However, you could place the same logic to dynamically create those fields in a subreport and pass a parameter too, but in general subreports do impose additional overhead (and an additional query in most cases) so I wouldn’t use a subreport unless there is a compelling benefit. However, there is a walkthrough on passing parameters to a subreport here.

    The only thing that looks suspect in your code is the following line:

     TB.Location =  new System.Drawing.PointF(Left, ((Label)rpt.Sections["PageHeader"].Controls["tbColorway1"]).Top);
    

    You are using the Top value from a control in the PageHeader, but TB is in the Detail section. I can understand reusing the Left value, but reusing the Top value wouldn’t be consistent across different sections (Top is it’s vertical position from the top of the section containing the control)

    Now, it sounds like sometimes these fields do not appear on the report. Some things you can verify to troubleshoot the problem:

    • Determine if there is a binding problem or a visual/location problem. TO do this, just give the textbox a border or a background color or something so you can see it even if there is no text (due to failed data binding).
    • Start logging out the position of each textbox and the datafield value to a log file. When you notice the problem, go back to the log and see if you can identify what triggers the problem (maybe a specific index, location or datafield value?).
    • Finally, make sure that the page size (determined by the system’s default printer) is not changing and maybe cutting off one of your dynamically added textboxes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if there is a better way to do this, so that is
Don't know how to google for such, but is there a way to query
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple
Don't know a whole lot about streams. Why does the first version work using
Don't know if this is the right place to ask this, but I will
Don't know why this is happening, but after submitting a form via JS (using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.