Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
475
Wingrid with Parent and Child row using IList
posted

Dear All,

I have a grid which uses an IList<T> as the datasource. In the IList, i have a columns like IncidentID and ParentIncidentID. Internally the relationship is assumed like If ParentIncidentID = 0 then it is a parent data, and if the ParentIncidentID != <incidentID#> then it is a child data of some incindent. I Want to bind all the parent data in band(0) and the child data in bands(1) by creating the relationship.

Sample Data

 

Incident ID            ParentIncidentID    createdOn

1                              0                               4/12/2009

2                              0                              4/12/2009

3                              1                              4/12/2009

 

So my output should like the ID 1 should be with a + symbol and when I click it should show the Id 3 data.

Any help on this would be greatly appreciated.

Thanks,

Arun.K.S

 

  • 469350
    Suggested Answer
    Offline posted

    Hi Arun,

    There's no way to create a relationship within the grid, it has to exist in the data source. In this case, your data source is an IList, which doesn't support relationships, but it does support hierarchical data.

    To get this to work with a List<T>, your class 'T' would have to have a public property that exposes a List<T> of child rows.

    Another option you might consider is using an UltraDataSource. You could set up the UltraDataSource with the hierarchical structure you want and then bind it to the grid in virtual mode. In this mode, then UDS will fire events when it needs data and you could get that data from your lists, building the relationship on the fly, so to speak.

  • 17259
    Offline posted

    You can use this code:

    IList<Incident> items = new List<Incident>();
    items.Add(new Incident() { IncidentID = 1, ParentIncidentID = 0 });
    items.Add(new Incident() { IncidentID = 2, ParentIncidentID = 0 });
    items.Add(new Incident() { IncidentID = 1, ParentIncidentID = 1 });

    ultraGrid1.DataSource = (from i in items
                             where i.ParentIncidentID == 0
                             select new
                             {
                                 i.IncidentID,
                                 i.ParentIncidentID,
                                 i.CreatedOn,
                                 Incidents = items.Where(i1 => i1.ParentIncidentID != 0 && i1.ParentIncidentID == i.IncidentID).ToList()
                             }).ToArray();

    So you didn't change your class, but you can't update the data back. You can also add an IList of incidents to your class, and put the children there in a loop:

    foreach (var item in items)
    {
        item.Incidents = items.Where(i => i.ParentIncidentID == item.IncidentID).ToList();           
    }
    ultraGrid1.DisplayLayout.MaxBandDepth = 2;
    ultraGrid1.DataSource = items.Where(i => i.ParentIncidentID == 0).ToList();