This is a migrated thread and some comments may be shown as answers.

Add TextBox in GroupHeader in RunTime

5 Answers 225 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jose Ferreira Lima Filho
Top achievements
Rank 1
Jose Ferreira Lima Filho asked on 03 Jun 2009, 03:56 PM
Hi,

  I want add textbox in header group in runtime, what wrong in my code?
private void gp_instrutor_header_ItemDataBinding(object sender, EventArgs e) 
        { 
            Telerik.Reporting.Processing.GroupSection groupb = (Telerik.Reporting.Processing.GroupSection)sender; 
 
            try 
            { 
                if (!dsSourceReport.Equals(null)) 
                { 
                     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"))); 
                } 
            } 
            catch { } 
        } 


My Function that generate the textbox colection

public static ReportItemBase[] AdicionaTextBoxDinamico(DataSet dsReportSource, string _strPrefixo, string _strTermoDescricao, string _strTermoValor, double _dblTamX, double _dblTamY, double _dblPosInicialX, double _dblPosInicialY, double _dblEspassamentoHorizontal, double _dblEspassamentoVertical) 
        { 
            try 
            { 
                #region Determinar a quantidade de colunas dinâmicas 
 
                int _intNumeroColunas = 0; 
 
                foreach (DataColumn coluna in dsReportSource.Tables[0].Columns) 
                { 
                    if (coluna.ColumnName.StartsWith(_strPrefixo)) 
                    { 
                        _intNumeroColunas++; 
                    } 
                } 
 
                _intNumeroColunas = _intNumeroColunas / 2; 
                #endregion 
                #region Monta Objetos(TextBox) que serão inseridos no relatório 
 
                TextBox txtDynamicColumnDescription; 
                TextBox txtDynamicColumnValue; 
                List lstControls = new List(); 
 
 
                for (int i = 1; i <= _intNumeroColunas; i++) 
                { 
                    if (!_strTermoDescricao.Equals("")) 
                    { 
                        #region Controle de Descrição (titulo do valor) 
 
                        txtDynamicColumnDescription = new TextBox(); 
                        txtDynamicColumnDescription.Name = _strPrefixo + "_" + _strTermoDescricao + "_" + i.ToString(); //ex.: curso_questao_1 
                        txtDynamicColumnDescription.Value = "=Fields." + _strPrefixo + "_" + _strTermoDescricao + "_" + i.ToString(); 
                        txtDynamicColumnDescription.Size = new SizeU(new Unit(_dblTamX, UnitType.Cm), new Unit(_dblTamY, UnitType.Cm)); 
                        txtDynamicColumnDescription.Style.Color = System.Drawing.Color.Black; 
                        txtDynamicColumnDescription.Style.Font.Bold = true
                        txtDynamicColumnDescription.Style.Font.Size = new Telerik.Reporting.Drawing.Unit(7, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Point))); 
                        txtDynamicColumnDescription.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center; 
                        txtDynamicColumnDescription.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle; 
 
                        if (i == 1) 
                        { 
                            txtDynamicColumnDescription.Location = new PointU(new Unit(_dblPosInicialX, UnitType.Cm), new Unit(_dblPosInicialY, UnitType.Cm)); 
                        } 
                        else 
                        { 
                            double _dblX, _dblY; 
 
                            ///Posição Inicial + espaçamento horizontal + tamanho do controle 
                            _dblX = ((_dblPosInicialX + _dblEspassamentoHorizontal) + (_dblTamX * (double.Parse(i.ToString()) - 1))); 
 
                            ///Mantém-se fixo, não variavél 
                            _dblY = _dblPosInicialY; 
 
                            txtDynamicColumnDescription.Location = new PointU(new Unit(_dblX, UnitType.Cm), new Unit(_dblY, UnitType.Cm)); 
                        } 
                        #endregion 
                        #region Adiciona Controles de Descrição no Array 
 
                        lstControls.Items.Add(txtDynamicColumnDescription); 
                        #endregion 
                    } 
 
                    if (!_strTermoValor.Equals("")) 
                    { 
                        #region Controle de Valores (Valores) 
 
                        txtDynamicColumnValue = new TextBox(); 
                        txtDynamicColumnValue.Name = _strPrefixo + "_" + _strTermoValor + "_" + i.ToString(); //ex.: curso_questao_1 
                        txtDynamicColumnValue.Value = "=Fields." + _strPrefixo + "_" + _strTermoValor + "_" + i.ToString(); 
 
                         
                        txtDynamicColumnValue.Size = new SizeU(new Unit(_dblTamX, UnitType.Cm), new Unit(_dblTamY, UnitType.Cm)); 
                        txtDynamicColumnValue.Style.Color = System.Drawing.Color.Blue; 
                        txtDynamicColumnValue.Style.Font.Bold = true
 
                        txtDynamicColumnValue.Style.Font.Size = new Telerik.Reporting.Drawing.Unit(7, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Point))); 
                        txtDynamicColumnValue.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center; 
                        txtDynamicColumnValue.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle; 
 
                        if (i == 1) 
                        { 
                            double _dblY; 
 
                            ///Posição Inicial + espaçamento vertical + tamanho do controle 
                            _dblY = (_dblPosInicialY + _dblEspassamentoVertical + _dblTamY); 
 
                            txtDynamicColumnValue.Location = new PointU(new Unit(_dblPosInicialX, UnitType.Cm), new Unit(_dblY, UnitType.Cm)); 
                        } 
                        else 
                        { 
                            double _dblX, _dblY; 
 
                            ///Posição Inicial + espaçamento horizontal + tamanho do controle 
                            _dblX = ((_dblPosInicialX + _dblEspassamentoHorizontal) + (_dblTamX * (double.Parse(i.ToString()) - 1))); 
 
                            ///Posição Inicial + espaçamento vertical + tamanho do controle 
                            _dblY = (_dblPosInicialY + _dblEspassamentoVertical + _dblTamY); 
 
                            txtDynamicColumnValue.Location = new PointU(new Unit(_dblX, UnitType.Cm), new Unit(_dblY, UnitType.Cm)); 
                        } 
                        #endregion 
                        #region Adiciona Controles de Valor no Array 
 
                        lstControls.Items.Add(txtDynamicColumnValue); 
                        #endregion 
                    } 
                } 
                #endregion 
                #region Array com todos os controles 
                    ReportItemBase[] reportControls = new ReportItemBase[lstControls.Items.Count]; 
                    for (int i = 0; i < lstControls.Items.Count; i++) 
                    { 
                        reportControls[i] = lstControls.Items[i]; 
                    } 
                #endregion 
 
                return reportControls; 
 
            } 
            catch (Exception error) 
            { 
                ///Lança a exeção gerada pelo método e retorna nulo; 
                throw new Exception(error.Message.ToString()); 
                return null
            } 
        } 


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

If I use this

Telerik.Reporting.Processing.GroupSection groupb = (Telerik.Reporting.Processing.GroupSection)sender; 
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






5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 04 Jun 2009, 01:03 PM
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.
0
Aleksey
Top achievements
Rank 1
answered on 25 Sep 2014, 03:08 PM
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
0
Stef
Telerik team
answered on 30 Sep 2014, 12:09 PM
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.

 
0
Aleksey
Top achievements
Rank 1
answered on 02 Oct 2014, 06:10 PM
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





0
Aleksey
Top achievements
Rank 1
answered on 02 Oct 2014, 09:00 PM
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
Tags
General Discussions
Asked by
Jose Ferreira Lima Filho
Top achievements
Rank 1
Answers by
Steve
Telerik team
Aleksey
Top achievements
Rank 1
Stef
Telerik team
Share this question
or