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

Setting table datasource to collection in parent

2 Answers 257 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Carl
Top achievements
Rank 1
Carl asked on 18 Nov 2009, 04:12 PM
Hello there,

I am creating a report whose datasource is an array of a custom object. I am displaying properties from my custom objects in text boxes successfully, however I also want to populate a table from a collection that is a property on my custom object.

If I use the NeedDataSource of the table I can't see how to access the current business object from the report's data source. If I try the following in the itemDataBinding the table does not get populated with any data:

        private void detail_ItemDataBinding(object sender, EventArgs e) 
        { 
            Log.Debug("detail_ItemDataBinding"); 
             DetailSection section = (DetailSection) sender; 
            MyObject c = section.DataObject.RawData as MyObject ; 
            tblHistory.DataSource = c.History; 
        } 

Please can anyone advise where I am going wrong?

Many thanks, Carl

2 Answers, 1 is accepted

Sort by
0
Carl
Top achievements
Rank 1
answered on 19 Nov 2009, 09:46 AM
Hi there,

I don't know if this is the best way of doing it, but i got around my issue by having a local variable of MyObject. In the detail_ItemDataBinding I lookup the current MyObject instance then assign it to the local variable. In the table's NeedDataSource event I hook it up to the collection on the local MyObject instance.

Cheers, Carl
0
Accepted
Svetoslav
Telerik team
answered on 19 Nov 2009, 03:27 PM
Hi Carl,

What you need to do is to use the exact Table item that belongs to the current detail section like this:

private void detail_ItemDataBinding(object sender, EventArgs e)
{
    var detail = sender as Telerik.Reporting.Processing.DetailSection;
    var processingTable = detail.ChildElements.Find("table1", true)[0] as Telerik.Reporting.Processing.Table;
     
    MyObject c = section.DataObject.RawData as MyObject ;
    processingTable.DataSource = c.History;
}

For complete explanation on using events in the Telerik Reporting engine please see Understanding Events help topic.

Kind regards,
Svetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Carl
Top achievements
Rank 1
Answers by
Carl
Top achievements
Rank 1
Svetoslav
Telerik team
Share this question
or