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

Hierarchy - Loading Child Table Dynamically

5 Answers 312 Views
GridView
This is a migrated thread and some comments may be shown as answers.
TechManagers
Top achievements
Rank 1
TechManagers asked on 06 May 2009, 09:37 PM
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?

5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 08 May 2009, 10:56 AM
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.
0
Andrew Stanford
Top achievements
Rank 1
answered on 05 Aug 2009, 03:35 PM
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?

0
Jack
Telerik team
answered on 06 Aug 2009, 12:34 PM
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.
0
Hannah
Top achievements
Rank 2
answered on 31 May 2013, 09:10 PM
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
0
Stefan
Telerik team
answered on 05 Jun 2013, 02:00 PM
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?
Tags
GridView
Asked by
TechManagers
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Andrew Stanford
Top achievements
Rank 1
Jack
Telerik team
Hannah
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or