Change TextBox DataField at runtime

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

  • 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
  • Marked as Answer

    Replied 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
    SectionReport_Runtime.zip
  • Replied 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
  • Replied 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"?>
    <ActiveReportsLayout Version="3.2" PrintWidth="13131.36" DocumentName="ActiveReports Document" ScriptLang="C#" MasterReport="0">
    <StyleSheet>
    <Style Name="Normal" Value="font-family: Arial; font-style: normal; font-variant: inherit; font-weight: normal; font-size: 10pt; font-size-adjust: inherit; font-stretch: inherit; color: rgb(0,0,0); background-image: inherit; background-repeat: inherit; background-attachment: inherit; opacity: inherit; word-spacing: inherit; letter-spacing: inherit; text-decoration: none; vertical-align: inherit; text-transform: inherit; text-align: inherit; text-indent: inherit; unicode-bidi: inherit; line-height: inherit; white-space: inherit; ddo-char-set: 0" />
    <Style Name="Heading1" Value="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: bold; font-size: 16pt; font-size-adjust: inherit; font-stretch: inherit" />
    <Style Name="Heading2" Value="font-family: Times New Roman; font-style: italic; font-variant: inherit; font-weight: bold; font-size: 14pt; font-size-adjust: inherit; font-stretch: inherit" />
    <Style Name="Heading3" Value="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: bold; font-size: 13pt; font-size-adjust: inherit; font-stretch: inherit" />
    </StyleSheet>
    <Sections>
    <Section Type="PageHeader" Name="PageHeader" Height="854.64" BackColor="16777215">
    <Control Type="AR.Label" Name="LabelRazonSocialEESS" Visible="0" Left="0" Top="0" Width="3787.2" Height="288" Caption="Razon social de la Estación de Servicios" Style="font-family: Century Gothic; font-size: 12pt; font-weight: bold; text-align: center" />
    <Control Type="AR.Label" Name="LabelVersion" Visible="0" Tag="3.6.0.13" Left="0" Top="0" Width="360" Height="288" Caption="" />
    </Section>
    <Section Type="Detail" Name="Detail" Height="8222.4" BackColor="16777215" KeepTogether="1">
    <Control Type="AR.Image" Name="PictureCodigoBarra" Visible="0" Left="105.12" Top="822.2401" Width="3682.08" Height="555.84" LineColor="16777215" LineWeight="0" />
    <Control Type="AR.Label" Name="LabelAnulacion" Visible="0" Left="105.12" Top="898.56" Width="3682.08" Height="1032.48" Caption="" Angle="45" />
    <Control Type="AR.Label" Name="LabelCliente" Visible="0" Left="105.12" Top="416.16" Width="1215.36" Height="288" Caption="Cliente:" Style="font-family: Century Gothic; font-size: 6.75pt; text-align: left" />
    <Control Type="AR.Field" Name="TextBoxRazonSocialCliente" DataField="RazonSocialCliente" Visible="0" Left="2040.48" Top="416.16" Width="1746.72" Height="288" Text="RazonSocial" Style="font-family: Century Gothic; font-size: 6.75pt" />
    <Control Type="AR.Field" Name="TextBoxCodigoCliente" DataField="CodigoCliente" Visible="0" Left="1320.48" Top="416.16" Width="720" Height="288" Text="Codigo" Style="font-family: Century Gothic; font-size: 6.75pt" />
    <Control Type="AR.Field" Name="TextBoxDocumentoCliente" DataField="DocumentoCliente" Visible="0" Left="1320.48" Top="1186.56" Width="1260" Height="288" Text="Documento" Style="font-family: Century Gothic; font-size: 8.25pt" />
    <Control Type="AR.Field" Name="TextBoxObservaciones" DataField="Observaciones" Visible="0" Left="105.12" Top="898.56" Width="3682.08" Height="479.5201" Text="Observaciones" Style="font-family: Century Gothic; font-size: 8.25pt" />
    <Control Type="AR.Label" Name="LabelObservaciones" Visible="0" Left="105.12" Top="2021.76" Width="0" Height="0" Caption="Observaciones:" Style="font-family: Century Gothic; font-size: 8.25pt; text-align: left" />
    <Control Type="AR.Field" Name="TextBoxPremio" Left="0" Top="0" Width="2760.48" Height="288" Text="PRE-8888-88888888" OutputFormat="#,##0" Style="font-size: 8.25pt; font-weight: bold; text-align: center" SummaryGroup="" />
    <Control Type="AR.Label" Name="LabelFecha" Left="105.12" Top="213.12" Width="1215.36" Height="288" Caption="Fecha:" Style="font-family: Century Gothic; font-size: 9pt; font-style: normal; text-align: left" />
    <Control Type="AR.Field" Name="TextBoxFecha" DataField="CodigoCliente" Left="1320.48" Top="213.12" Width="2466.72" Height="288" Text="Fecha" OutputFormat="dd/MM/yyyy h:mm" Style="font-family: Century Gothic; font-size: 11.25pt; font-style: normal; font-weight: bold" SummaryGroup="" SummaryDistinct="" />
    <Control Type="AR.Line" Name="Line" X1="0" Y1="213.12" X2="3787.2" Y2="213.12" />
    <Control Type="AR.Label" Name="LabelEstado" Left="90.72" Top="704.16" Width="4116.96" Height="4320" Caption="" Style="font-family: Arial; font-size: 6.75pt; font-weight: bold; text-align: center; vertical-align: middle; ddo-char-set: 0" />
    <Control Type="AR.Field" Name="TextBoxEstado" Visible="0" Left="1635.84" Top="1643.04" Width="2151.36" Height="288" Text="Estado" Style="font-family: Century Gothic; font-size: 8.25pt" />
    <Control Type="AR.CheckBox" Name="CheckBoxRescatado" Visible="0" Left="1320.48" Top="1643.04" Width="315.3605" Height="288" Caption="" ContentAlign="32" />
    <Control Type="AR.Field" Name="TextBoxFecha2" DataField="=System.DateTime.Now.ToString()" Left="5040" Top="288" Width="2466.72" Height="288" Text="Fecha" OutputFormat="MM/dd/yyyy" Style="font-family: Century Gothic; font-size: 11.25pt; font-style: normal; font-weight: bold" SummaryGroup="" SummaryDistinct="" />
    <Control Type="AR.Field" Name="TextBoxFecha3" DataField="=System.DateTime.Now.ToString()" Left="10131.84" Top="288" Width="2466.72" Height="288" Text="Fecha" OutputFormat="MM/dd/yyyy" Style="font-family: Century Gothic; font-size: 11.25pt; font-style: normal; font-weight: bold" SummaryGroup="" SummaryDistinct="" />
    <Control Type="AR.Field" Name="TextBoxPremio2" DataField="TextBoxPremio.Value" Tag="" Left="5040" Top="0" Width="2760.48" Height="288" Text="" OutputFormat="" Style="font-size: 8.25pt; font-weight: bold; text-align: center" SummaryFunc="2" SummaryGroup="" SummaryDistinct="" CountNullValues="1" />
    </Section>
    <Section Type="PageFooter" Name="PageFooter" Height="0" BackColor="16777215" />
    </Sections>
    <ReportComponentTray />
    <PageSettings LeftMargin="144" RightMargin="144" TopMargin="43" BottomMargin="144" PaperSize="0" PaperWidth="4752" PaperHeight="13680" PaperName="Custom paper" />
    <Parameters />
    </ActiveReportsLayout>
  • Replied 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