Change TextBox DataField at runtime

Posted by: softcomlimited on 6 August 2019, 3:56 am EST

    • Post Options:
    • Link

    Posted 6 August 2019, 3:56 am EST

    Hello,

    I have a v12 Section report with all the textbox bound to a SQL query. I want to be able to change the setup of the report at runtime, changing the DataField of one of the textboxes from query column A to query column B, depending on a condition in the ReportStart.

    My alternative is to have 2 separate sets of fields (detail and summary) and hide the A fields or B fields based on the condition.

    Regards

    Brian

  • Posted 6 August 2019, 10:34 pm EST

    Hello Brian,

    If the condition that you use is predefined (i.e., not based on data value from the report), you can achieve both of the mentioned requirements in the ReportStart. For example, you can set the DataField conditionally as follows:

    ```

    int i = 5, j = 10;

    if (i > j)

    textBox3.DataField = “CustomerId”;

    else

    textBox3.DataField = “Country”;

      
    If the condition is based on the report related values, you can achieve the requirement to hide controls conditionally in Detail.Format event as follows:
    
    

    private void detail_Format(object sender, EventArgs e)

    {

    if (textBox1.Value.ToString().StartsWith(“B”) || textBox1.Value.ToString().StartsWith(“D”))

    {

    textBox3.Visible = true;

    textBox4.Visible = false;

    }

    else

    {

    textBox3.Visible = false;

    textBox4.Visible = true;

    }

    }

    A sample has been attached for your reference.
    
    Regards,
    Esha
    [zip filename="SectionReport_Runtime.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-5ca7bcf8-04f1-4936-8251-22eb53be9a65.zip[/zip]
  • Posted 7 August 2019, 8:40 am EST

    Ms Dhir,

    I had tried exactly these same 2 methods and only the 2nd was working. But the first is what I really wanted.

    After some checking I think the first was not working for me because I was looking for a value in a textbox and it was not populating as yet. I will have to get the value from the datasource directly instead.

    Thank you very much

    Regards

    Brian Morris

  • Posted 14 May 2021, 6:20 am EST

    Hi! I have the following problem, I want to send the value of the TextBoxPremio to TextBoxPremio2. The way it is done, it does not take that value to print it. Can you help me?

    <?xml version="1.0" encoding="UTF-8"?>
  • Posted 17 May 2021, 3:14 pm EST

    Hello,

    You can use the Format event of the Detail Section to achieve your requirement:

    public void Detail_Format()
    {
    	this.TextBoxPremio2.Text = this.TextBoxPremio.Text;
    }
    
    

    Please refer to the modified image.

    Thanks,

    Mohit

    ytest.zip

Need extra support?

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

Learn More

Forum Channels