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

Populating the GridView with variable number of columns from custom data source

5 Answers 211 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Domagoj
Top achievements
Rank 1
Domagoj asked on 10 Jun 2011, 12:04 PM
I have a problem with the RadGridView because I need to set column names manually, and I don't have a constant number of columns.
I have a data class that looks something like this:
public class MyItemData
{
  public DateTime Time {get; set; }
  public List<int> Values {get; set; }
  public List<string> ColumnNames { get; set; }
}

And then I have the following list with the actual data:

public void PopulateGrid()
{
  List<MyItemData> data = DB.GetData();
 
  // Populate grid from data...
  // ...
}

The problem is that I want the GridView to show one column for Time property (I can bind this to MyItemData.Time), but I also want a column for each element in the Values list, named by corresponding name in ColumnNames list. That means that I can't bind the other columns to object properties, as there are no objects that can contain variable number of properties. I have values for each column (with the names in the separate list) in the MyItemData.Values list, but I don't know how to populate the GridView from such data source. And I can't find any way to populate rows by column index.

What would be the right approach for populating the GridView with a data source like this?

Note: I don't need any editing possibilities, I just need to represent the data.

5 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 10 Jun 2011, 01:13 PM
Hello Domagoj,

I have prepared an example project that implements the described behavior. Would you please have a look at it and inform me if this approach meets you requirements?

All the best,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ronald
Top achievements
Rank 2
answered on 17 Jun 2011, 03:34 PM
Hi Ivan,

thanks for this example, this is almost exactly what I need!
I'm working on a POC and I want to incorporate Telerik controls for this WPF/Silverlight project.

But we need (multi-column) sort and filtering. Is it possible to extend this example with this functionality?
I receive the exception: At least one object must implement IComparable. I'm a little bit lost how to implement this in this example.

So if you could help me?

Best regards,
Ronald
(Hope I'm not hijacking this thread.)

0
Domagoj
Top achievements
Rank 1
answered on 20 Jun 2011, 08:17 AM
Hi,
I just wanted to inform you that I have successfully implemented the desired behaviour by following your example.
Thank you very much.
0
Ivan Ivanov
Telerik team
answered on 20 Jun 2011, 08:52 AM
Hi Domagoj,

I am glad to read that my example has proved useful for your case. Please, do not hesitate to contact us if any further inquiries occur. As for Ronald's question, I have prepared a modified version that implements filtering and sorting. It is attached for your reference.

Best wishes,
Ivan Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ronald
Top achievements
Rank 2
answered on 20 Jun 2011, 09:45 AM
Hello Ivan, thanks for the quick and excelent response!
I can now provide answers to all requirements of the gridcontrol we need.

Best regards,
Ronald
Tags
GridView
Asked by
Domagoj
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Ronald
Top achievements
Rank 2
Domagoj
Top achievements
Rank 1
Share this question
or