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

Set Table column headings from DataTable column headings

1 Answer 383 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kevin Y
Top achievements
Rank 1
Kevin Y asked on 10 Nov 2011, 07:01 PM
I have created a Report in the Designer which contains a Table with a fixed number of columns.  When I added the columns, it set the column heading to the default "string= same as the database field name".  In the application, we create a DataTable object(called DetailsTable) populating the column headings from a resource file and the table rows with the data.  The Report DataSource is set through the NeedDataSource event shown.

What I would like to know is what expression can I use to bring in the column headings from the DataTable object?
The objective is to remove all "hardcoded" strings from our reports.

private void table1_NeedDataSource_1(object sender, EventArgs e)
{
    var objectDataSource = new ObjectDataSource();
    objectDataSource.DataSource = ((BestFitStepDetailsReportView)this.DataSource).StepDetailsTable;
    (sender as Processing.Table).DataSource = objectDataSource;
}


1 Answer, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 11 Nov 2011, 05:13 PM
Hello Kevin Y,

Since your table is static the data source does not need to be set at run-time. You can easily achieve the same result using a simple binding ( I have attached a screenshot of the table binding). The property "Friends" represents your "StepDetailsTable". About the column headers they can be set in the Report() constructor after the InitializeComponent();

 public Report1()         
{           
	InitializeComponent();   

	//get my custom collection of header names          
	var headings = DataSourceClass.GetTable1Headings();            
	int i = 0;             
	foreach (var cg in table1.ColumnGroups)             
	{                
		var reportItem = cg.ReportItem as Telerik.Reporting.TextBox;
		reportItem.Value = headings[i];                 
		i++;          
	}       
}

You can take a look at the sample project that I have attached.

Regards,
Elian
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

Tags
General Discussions
Asked by
Kevin Y
Top achievements
Rank 1
Answers by
Elian
Telerik team
Share this question
or