Hierarchy - Loading Child Table Dynamically

6 posts, 0 answers
  1. Tom Ottman
    Tom Ottman avatar
    4 posts
    Member since:
    Feb 2007

    Posted 06 May 2009 Link to this post

    I have the gridview working fine in hierarchy mode when I load both datatables into a dataset.  This requires all of the child records to get loaded at the beginning (before any + has been selected).

    What I want to do is only load the child records as they are requested.

    I tied into the ChildViewExpanding event with the following code.

    DataSet

     

    ds = (DataSet)radGridViewMain.MasterGridViewTemplate.DataSource;

     

     

    DataTable dt = ds.Tables["Details"];

     

     

    int headerID = Convert.ToInt32(e.ParentRow.Cells["ID"].Value);

     

     

    Details dtl = new Details();

     

     

    DataRow[] dr = dt.Select(String.Format("HeaderID={0}", headerID));

     

     

    if (dr.Length <= 0)

     

    {

        dt.Merge(dtl.GetRecords(headerID),

    true);

     

    }

    Works great the on the first + selected, but as soon as I select another row's children to display the first childset is cleared out.

    How do I load the child recrods dynamically?  Any samples on that?

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 08 May 2009 Link to this post

    Hello Tom Ottman,

    The current edition of radGridView does not support this feature. Your approach is very interesting, but RadGridView cannot guarantee the correct processing in this situation. Please try to add this source line in your code at the end:

    radGridView.MasterGridViewTemplate.ChildGridViewTemplates[0].Update(GridUINotifyAction.HierarchyChanged); 

    Do not hesitate to write us back if you have further questions.

    Regards,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Andrew Stanford
    Andrew Stanford avatar
    7 posts
    Member since:
    Jul 2009

    Posted 05 Aug 2009 Link to this post

    I have just been assessing the product and I was thinking this would be a very common requirement. For example, we group companies we sell parts to so we can apply discounts etc. We have about 40,000 CompanyGroups and these link to about 60,000 Companies. Obviously for performance reasons one wouldn't even consider loading all of these as the form loads. I set my relationship between them at design time.

    To keep the application memory to a minimum on the client the top level data (i.e. Company Group) is loaded 50 records at a time. My thinking was to keep a small cache of associated Companies and add records to it as the user expands the group and remove records as it is collapsed.

    Here is the code;

     

     

            private void radGridView1_ChildViewExpanding(object sender, Telerik.WinControls.UI.ChildViewExpandingEventArgs e)  
            {  
                int companyGroupId = 0;  
                Company testExists=null;  
                if (e.ParentRow.Cells[0].Value != null )  
                {  
                    companyGroupId = (int)e.ParentRow.Cells[0].Value;  
                    if (e.IsExpanded)  
                    {  
                        //already got the data, so remove from local cache  
                        TList<Company> removeList = companyList.FindAll(CompanyColumn.CompanyGroupId, companyGroupId);  
                        foreach (Company c in removeList)  
                        {  
                            companyList.Remove(c);  
                        }  
                    }  
                    else 
                    {  
                        testExists = companyList.Find(CompanyColumn.CompanyGroupId, companyGroupId);  
                        if (testExists == null)  
                        {  
                            //None on list for this one yet  
                            companyList.AddRange(companyService.GetByCompanyGroupId(companyGroupId));  
                            //THIS DOESN'T REFRESH radGridView1.MasterGridViewTemplate.ChildGridViewTemplates[0].Update(Telerik.WinControls.UI.GridUINotifyAction.HierarchyChanged);  
                            //THIS DOESN'T EITHER radGridView1.MasterGridViewTemplate.ChildGridViewTemplates[0].Update(Telerik.WinControls.UI.GridUINotifyAction.Reset);  
                        }  
                    }  
                }  
            } 


    So this begs the question; how do we force the child grid to refresh?

  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 06 Aug 2009 Link to this post

    Hi Andrew Stanford,

    I understand you concerns. Generally 60,000 records is not a big number and RadGridView will consume less than 70 megabytes to show the hierarchy. Nevertheless, you scenario is possible. However, I suggest using a BindingList instead of a TList. This way RadGridView will be able to monitor all changes in the list and will react automatically. If this doesn't help, please send us your application and we will try to locate the issue.

    Also, you can work around the issue by using the grid API directly. Here is a sample:

    void radGridView1_ChildViewExpanding(object sender, ChildViewExpandingEventArgs e) 
        if (e.IsExpanded) 
        { 
            this.radGridView1.GridElement.BeginUpdate(); 
            while (e.ParentRow.ViewTemplate.ChildGridViewTemplates[0].Rows.Count > 0) 
                e.ParentRow.ViewTemplate.ChildGridViewTemplates[0].Rows.RemoveAt(0); 
            this.radGridView1.GridElement.EndUpdate(); 
        } 
        else 
        { 
            Random r = new Random(); 
            for (int i = 0; i < 10; i++) 
            { 
                e.ParentRow.ViewTemplate.ChildGridViewTemplates[0].Rows.Add(i, e.ParentRow.Cells[0].Value, r.Next(100)); 
            } 
        } 

    Please tell me whether this helps. I will be glad to assist you further and I am looking forward to your reply.

    Kind regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Hannah
    Hannah avatar
    37 posts
    Member since:
    May 2013

    Posted 31 May 2013 Link to this post

    Any change or update to this particular issue?  I'm currently throwing OutOfMemoryException errors and looking to deal with it in some way.  This is while expanding a row with 300k+ child rows...  :)

    Thanks,

    Wayne
  6. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 05 Jun 2013 Link to this post

    Hi,

    If I understand correctly you are asking whether load-on-demand functionality is implemented in RadGridView. If so, the answer is yes. You can find more information about this functionality at the following article: http://www.telerik.com/help/winforms/gridview-hierarchical-grid-load-on-demand-hierarchy.html

    I hope that you find this information useful.
     

    Regards,
    Stefan
    Telerik
    RadChart for WinForms is obsolete. Now what?
Back to Top