or
public Table DataGrid() { Table table = new Table(); // Get data and bind it to the table System.Data.DataTable data = ChartsData.chartTable(); // Clear table before binding table.ColumnGroups.Clear(); table.Body.Columns.Clear(); table.Body.Rows.Clear(); table.DataSource = data; int colCount = data.Columns.Count; for (int i = 0; i <= colCount - 1; i++) { TableGroup tableGroupColumn = new TableGroup(); table.ColumnGroups.Add(tableGroupColumn); //table.Body.Columns.Add(new TableBodyColumn(Unit.Inch(0.01))); HtmlTextBox txtGroup = new HtmlTextBox() { Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3)), Value = data.Columns[i].ColumnName, Style = { BorderStyle = { Default = BorderType.Solid }, BorderColor = { Default = System.Drawing.Color.Black }, Font = { Name = "Arial", Size = new Unit(10) }, VerticalAlign = VerticalAlign.Middle }, }; tableGroupColumn.ReportItem = txtGroup; HtmlTextBox txtTable = new HtmlTextBox() { Size = new SizeU(Unit.Inch(1.1), Unit.Inch(0.3)), Value = "=Fields." + data.Columns[i].ColumnName, Style = { BorderStyle = { Default = BorderType.Solid }, BorderColor = { Default = System.Drawing.Color.Black }, BorderWidth = { Default = new Unit(0.5, UnitType.Point) } } }; table.Body.SetCellContent(0, i,txtTable); table.Items.AddRange(new ReportItemBase[] { txtTable, txtGroup }); } return table; }Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString<br><connectionStrings><br> <add name="Telerik.Reporting.Examples.CSharp.Properties.Settings.TelerikConnectionString"<br> connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=myDB;User Id=xxxx;Password=xxxx"<br> providerName="System.Data.SqlClient" /><br></connectionStrings>Format of the initialization string does not conform to specification starting at index 0| 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 { } | |
| } |
| 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; | |
| } | |
| } |
| Telerik.Reporting.Processing.GroupSection groupb = (Telerik.Reporting.Processing.GroupSection)sender; | |
| groupb.Items.Add(item); |