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

6 posts, 1 answers
  1. Domagoj
    Domagoj avatar
    17 posts
    Member since:
    Jun 2011

    Posted 10 Jun 2011 Link to this post

    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.
  2. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 10 Jun 2011 Link to this post

    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
  3. DevCraft banner
  4. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 17 Jun 2011 Link to this post

    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.)

  5. Domagoj
    Domagoj avatar
    17 posts
    Member since:
    Jun 2011

    Posted 20 Jun 2011 Link to this post

    Hi,
    I just wanted to inform you that I have successfully implemented the desired behaviour by following your example.
    Thank you very much.
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 20 Jun 2011 Link to this post

    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
  7. Ronald
    Ronald avatar
    21 posts
    Member since:
    Dec 2007

    Posted 20 Jun 2011 Link to this post

    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
Back to Top
DevCraft banner