Add TextBox in GroupHeader in RunTime

6 posts, 0 answers
  1. Jose Ferreira Lima Filho
    Jose Ferreira  Lima Filho avatar
    10 posts
    Member since:
    Jun 2008

    Posted 03 Jun 2009 Link to this post

    Hi,

      I want add textbox in header group in runtime, what wrong in my code?
    1 private void gp_instrutor_header_ItemDataBinding(object sender, EventArgs e) 
    2         { 
    3             Telerik.Reporting.Processing.GroupSection groupb = (Telerik.Reporting.Processing.GroupSection)sender; 
    4  
    5             try 
    6             { 
    7                 if (!dsSourceReport.Equals(null)) 
    8                 { 
    9                      gp_instrutor_header.Items.AddRange(Report_Functions.clsReportFunctions.AdicionaTextBoxDinamico(dsSourceReport, "INSTRUTOR""DS_GRUPO_QUESTAO""VL_MEDIA"double.Parse("3,2"), double.Parse("0,4"), double.Parse("9,5"), double.Parse("0,85"), double.Parse("0,2"), double.Parse("0,1"))); 
    10                 } 
    11             } 
    12             catch { } 
    13         } 


    My Function that generate the textbox colection

    1 public static ReportItemBase[] AdicionaTextBoxDinamico(DataSet dsReportSource, string _strPrefixo, string _strTermoDescricao, string _strTermoValor, double _dblTamX, double _dblTamY, double _dblPosInicialX, double _dblPosInicialY, double _dblEspassamentoHorizontal, double _dblEspassamentoVertical) 
    2         { 
    3             try 
    4             { 
    5                 #region Determinar a quantidade de colunas dinâmicas 
    6  
    7                 int _intNumeroColunas = 0; 
    8  
    9                 foreach (DataColumn coluna in dsReportSource.Tables[0].Columns) 
    10                 { 
    11                     if (coluna.ColumnName.StartsWith(_strPrefixo)) 
    12                     { 
    13                         _intNumeroColunas++; 
    14                     } 
    15                 } 
    16  
    17                 _intNumeroColunas = _intNumeroColunas / 2; 
    18
    19                 #endregion 
    20
    21                 #region Monta Objetos(TextBox) que serão inseridos no relatório 
    22  
    23                 TextBox txtDynamicColumnDescription; 
    24                 TextBox txtDynamicColumnValue; 
    25                 List lstControls = new List(); 
    26  
    27  
    28                 for (int i = 1; i <= _intNumeroColunas; i++) 
    29                 { 
    30                     if (!_strTermoDescricao.Equals("")) 
    31                     { 
    32                         #region Controle de Descrição (titulo do valor) 
    33  
    34                         txtDynamicColumnDescription = new TextBox(); 
    35                         txtDynamicColumnDescription.Name = _strPrefixo + "_" + _strTermoDescricao + "_" + i.ToString(); //ex.: curso_questao_1 
    36                         txtDynamicColumnDescription.Value = "=Fields." + _strPrefixo + "_" + _strTermoDescricao + "_" + i.ToString(); 
    37                         txtDynamicColumnDescription.Size = new SizeU(new Unit(_dblTamX, UnitType.Cm), new Unit(_dblTamY, UnitType.Cm)); 
    38                         txtDynamicColumnDescription.Style.Color = System.Drawing.Color.Black; 
    39                         txtDynamicColumnDescription.Style.Font.Bold = true
    40                         txtDynamicColumnDescription.Style.Font.Size = new Telerik.Reporting.Drawing.Unit(7, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Point))); 
    41                         txtDynamicColumnDescription.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center; 
    42                         txtDynamicColumnDescription.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle; 
    43  
    44                         if (i == 1) 
    45                         { 
    46                             txtDynamicColumnDescription.Location = new PointU(new Unit(_dblPosInicialX, UnitType.Cm), new Unit(_dblPosInicialY, UnitType.Cm)); 
    47                         } 
    48                         else 
    49                         { 
    50                             double _dblX, _dblY; 
    51  
    52                             ///Posição Inicial + espaçamento horizontal + tamanho do controle 
    53                             _dblX = ((_dblPosInicialX + _dblEspassamentoHorizontal) + (_dblTamX * (double.Parse(i.ToString()) - 1))); 
    54  
    55                             ///Mantém-se fixo, não variavél 
    56                             _dblY = _dblPosInicialY; 
    57  
    58                             txtDynamicColumnDescription.Location = new PointU(new Unit(_dblX, UnitType.Cm), new Unit(_dblY, UnitType.Cm)); 
    59                         } 
    60
    61                         #endregion 
    62
    63                         #region Adiciona Controles de Descrição no Array 
    64  
    65                         lstControls.Items.Add(txtDynamicColumnDescription); 
    66
    67                         #endregion 
    68                     } 
    69  
    70                     if (!_strTermoValor.Equals("")) 
    71                     { 
    72                         #region Controle de Valores (Valores) 
    73  
    74                         txtDynamicColumnValue = new TextBox(); 
    75                         txtDynamicColumnValue.Name = _strPrefixo + "_" + _strTermoValor + "_" + i.ToString(); //ex.: curso_questao_1 
    76                         txtDynamicColumnValue.Value = "=Fields." + _strPrefixo + "_" + _strTermoValor + "_" + i.ToString(); 
    77  
    78                          
    79                         txtDynamicColumnValue.Size = new SizeU(new Unit(_dblTamX, UnitType.Cm), new Unit(_dblTamY, UnitType.Cm)); 
    80                         txtDynamicColumnValue.Style.Color = System.Drawing.Color.Blue; 
    81                         txtDynamicColumnValue.Style.Font.Bold = true
    82  
    83                         txtDynamicColumnValue.Style.Font.Size = new Telerik.Reporting.Drawing.Unit(7, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Point))); 
    84                         txtDynamicColumnValue.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center; 
    85                         txtDynamicColumnValue.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle; 
    86  
    87                         if (i == 1) 
    88                         { 
    89                             double _dblY; 
    90  
    91                             ///Posição Inicial + espaçamento vertical + tamanho do controle 
    92                             _dblY = (_dblPosInicialY + _dblEspassamentoVertical + _dblTamY); 
    93  
    94                             txtDynamicColumnValue.Location = new PointU(new Unit(_dblPosInicialX, UnitType.Cm), new Unit(_dblY, UnitType.Cm)); 
    95                         } 
    96                         else 
    97                         { 
    98                             double _dblX, _dblY; 
    99  
    100                             ///Posição Inicial + espaçamento horizontal + tamanho do controle 
    101                             _dblX = ((_dblPosInicialX + _dblEspassamentoHorizontal) + (_dblTamX * (double.Parse(i.ToString()) - 1))); 
    102  
    103                             ///Posição Inicial + espaçamento vertical + tamanho do controle 
    104                             _dblY = (_dblPosInicialY + _dblEspassamentoVertical + _dblTamY); 
    105  
    106                             txtDynamicColumnValue.Location = new PointU(new Unit(_dblX, UnitType.Cm), new Unit(_dblY, UnitType.Cm)); 
    107                         } 
    108
    109                         #endregion 
    110
    111                         #region Adiciona Controles de Valor no Array 
    112  
    113                         lstControls.Items.Add(txtDynamicColumnValue); 
    114
    115                         #endregion 
    116                     } 
    117                 } 
    118
    119                 #endregion 
    120
    121                 #region Array com todos os controles 
    122                     ReportItemBase[] reportControls = new ReportItemBase[lstControls.Items.Count]; 
    123                     for (int i = 0; i < lstControls.Items.Count; i++) 
    124                     { 
    125                         reportControls[i] = lstControls.Items[i]; 
    126                     } 
    127                 #endregion 
    128  
    129                 return reportControls; 
    130  
    131             } 
    132             catch (Exception error) 
    133             { 
    134                 ///Lança a exeção gerada pelo método e retorna nulo; 
    135                 throw new Exception(error.Message.ToString()); 
    136                 return null
    137             } 
    138         } 


    The problem is that on runtime its don´t render the controls.How can I do it?

    If I use this

    1 Telerik.Reporting.Processing.GroupSection groupb = (Telerik.Reporting.Processing.GroupSection)sender; 
    2 groupb.Items.Add(item); 


    What data type my function need return, or how can I make a foreach loop whit an Telerik.Reporting.ReportItemBase array.

    Thanks






  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 04 Jun 2009 Link to this post

    Hi Jose,

    We've already answered your inquiry in the support thread you've opened.

    All the best,
    Steve
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Aleksey
    Aleksey avatar
    3 posts
    Member since:
    Sep 2014

    Posted 25 Sep 2014 in reply to Steve Link to this post

    Hi Steve,

    Could you please provide a link to the answer given to Jose. I have similar issue trying to add a text box to the group header in RunTime.

    Thanks,
    Aleksey
  4. Stef
    Admin
    Stef avatar
    3610 posts

    Posted 30 Sep 2014 Link to this post

    Hi Aleksey,

    In general, the report is a template repeated for the data assigned to it. It is not recommended to modify this template once the data processing has started (e.g. in events).

    At run-time you can create an instance of the report, create an item and add it to the desired section of the report:
    var tb = new Telerik.Reporting.TextBox();
     
    tb.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm));
    tb.Name = "uniqueTextBoxName";
    tb.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.0, Telerik.Reporting.Drawing.UnitType.Cm), new Telerik.Reporting.Drawing.Unit(0.6, Telerik.Reporting.Drawing.UnitType.Cm));
    tb.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid;
     
    //set the value of the Textbox to an expression for example
    tb.Value = "=Fields.MyFieldName";
     
     
    //create an instance of the report
    var report = new MyReport();
     
    //get the group header section by name
    var section = report.Items.Find("groupHeaderSection1",true)[0] as Telerik.Reporting.GroupHeaderSection;
    section.Items.Add(tb);
     
    //display the report
    reportViewer1.ReportSource = new InstanceReportSource { ReportDocument = report };

    Before modifying/creating a report definition at run-time, test the structure by using the integrated in Visual Studio Report Designer. Not all sections allow you to use data items for example.


    I hope the above information is helpful.

    Regards,
    Stef
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Aleksey
    Aleksey avatar
    3 posts
    Member since:
    Sep 2014

    Posted 02 Oct 2014 in reply to Stef Link to this post

    Hi Stef,

    The information you provided is very helpful. Thanks. It works just fine, but it does work from the calling application.
    I try to find a way to add a textbox (B) to the groupheader with location based on the width of another textbox (A) neighboring on the textbox B's left. Simply put I have textbox A with flexible width and I need to place textbox B next to textbox A being tide to its width. So, when textbox A contains longer string it will push textbox B to the right. This way I will not have a huge gap between A and B when string in A is quite short.
    Accessing textbox A from calling application I am getting its design width, so I thought I needed to access it from the report itself. 
    But I still am getting the same width value as it was designed.

    private void groupHeaderSection1_ItemDataBinding(object sender, EventArgs e)
            {
                Telerik.Reporting.Processing.GroupSection section = (sender as Telerik.Reporting.Processing.GroupSection);
                Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(section, "sERIES_TYPEDataTextBox");

                string width = txt.Width.ToString();

                // create textbox
                Telerik.Reporting.TextBox textBox1 = new Telerik.Reporting.TextBox();

                textBox1.CanGrow = true;
                textBox1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(5.7D), Telerik.Reporting.Drawing.Unit.Inch(0));
                textBox1.Name = "textBox6";
                textBox1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.70D), Telerik.Reporting.Drawing.Unit.Inch(0.20D));
                textBox1.StyleName = "Data";
                textBox1.Value = width;

                detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { textBox1 });
                
            }

    BTW the method "Items" (section.Items.Add(textBox1);) does not exist for the section at the ItemDataBinding event, so I had to place that textbox to the detail section (just for testing).

    Thanks,
    Aleksey





  6. Aleksey
    Aleksey avatar
    3 posts
    Member since:
    Sep 2014

    Posted 02 Oct 2014 in reply to Aleksey Link to this post

    UPDATE:

    I resolved my issue by using a single HTMLTextBox and formatting text fonts and colors there:

    <span style="color: #f22f34" size="4"><b>{ToUpper(IsNull(Fields.SERIES_TYPE, "Other"))}</b></span>&nbsp;<span style="color: #808080" size="3">{IsNull(Fields.SERIES, "Other") + ShortDescription(Fields.PROD_SHORT_DESC)}</span>

    Thanks,
    Aleksey
Back to Top