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

How to bind to arbitrary number of columns?

2 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 06 Sep 2011, 04:10 PM
I have the following requirement.

Create a grid that contains three defined columns (Category, Class and Measure).  From here, there can be an arbitrary number of columns representing locations.  Each cell will contain a value for the Category, Class and Measure.

So, as an example:

On one run of the report for this grid, I may have 5 locations.  So I would need columns Category, Class, Measure, Location1, Location2, Location3, Location4, Location5.

On the next run, I may have 2 locations.  So I would need columns Category, Class, Measure, Location1, Location2.

The values for each measure will be a text string so I do not need a checkbox or other "fancy" control.

The data for my grid will come from two data source, both returned from WCF Data Service Calls back to my Silverlight application.  The first dataset contains the definition of the Category, Class and Measures and the second data set contains a row for each location.

I have built a class in my Silverlight application to merge the data from both service calls to bind to the RadGridView as its ItemsSource.  However, this limits me to a finite, known number of locations.  Is there a way to dynamically create columns 3 through 0, where col0 is Category, col1 is Class and col2 is Measure?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 07 Sep 2011, 05:33 PM
Ok, so I figured out how to accomplish this.  I defined my three static columns and then loop through my list of locations adding a new column for each one.  Then in my RowLoaded event handler, I pull the necessary data to populate the current row and walk to the different cells in the row to fill in the associated data.

However, now I am trying to export the information in the grid to an Excel document using the Export feature of the grid.  It exports the three static columns with the correct values.  However, for my dynamic columns, it is exporting the object name that stores the data that is placed in the cell.  How do I get it to export the actual value instead?

Thanks.
0
Vanya Pavlova
Telerik team
answered on 09 Sep 2011, 03:06 PM
Hello Chris,

 


I am glad to hear that you were able to resolve some of the issues by your side. 
Regarding your question about exporting dynamic columns you may use the approach demonstrated in the following forum thread. 


Hope this helps!



Regards,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Share this question
or