GridView Performance

2 posts, 1 answers
  1. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Hi,

    I've got a gridview with a 3level hierarchy.

    When loading the view with :

    first level: 300 elements
    second level: 10 elements
    third level: 5 elements

    the load goes fast.

    But if I'm trying the following load:

    first level: 2100 elements
    second level: 10 elements
    third level: 5 elements

    the load goes slow...

    I think I had to wait for 10 - 15 minutes before everything was loaded.

    Is this due to bad programming or something else?

    my code:

    1 var sortedByLft = from c in network 
    2                   where (c.Rgt - c.Lft) == 1 
    3                   orderby c.Name ascending 
    4                   select c; 
    5  
    6 var checkNetwork = new List<Network>(); 
    7 //display the unique items in the gridview 
    8 foreach (var item in sortedByLft) 
    9 {     
    10     Application.DoEvents(); 
    11     //check if item is already added 
    12     var check = checkNetwork.Find(p => p.Adserver_id == item.Adserver_id); 
    13     if (check != nullcontinue
    14     checkNetwork.Add(item); 
    15     Application.DoEvents(); 
    16  
    17     rgvAdlPositions.MasterGridViewTemplate.Rows.Add(new object[] { item.Adserver_id, item.Name }); 
    18     var template = rgvAdlPositions.MasterGridViewTemplate.ChildGridViewTemplates[0]; 
    19     foreach(var position in item.Positions) 
    20     { 
    21         Application.DoEvents(); 
    22         //get the method as string 
    23         var method = Enums.GetMethod(position.Method); 
    24         //add to row 
    25         template.Rows.Add(new object[] 
    26                               { 
    27                                   item.Adserver_id, position.PosId, 
    28                                   ownFunctions.ConcatStrings(new List<string
    29                                                                           { 
    30                                                                               position.Name, 
    31                                                                               position.Width.ToString(), 
    32                                                                               "x"
    33                                                                               position.Height.ToString() 
    34                                                                           }), 
    35                                   method 
    36                               }); 
    37         var templateAd = template.ChildGridViewTemplates[0]; 
    38         foreach(var adPos in position.adserverPositions) 
    39         { 
    40             //add adserved position to row 
    41             templateAd.Rows.Add(new object[] { item.Adserver_id, position.PosId, adPos.name }); 
    42         } 
    43     } 
    44

    Is it possible that the lines 12 and 28 are the bad ones?
    the first one is checking if I have unique elements and the second one is calling a static function to concatenate a list of strings.

    Thanks a lot in advanced


  2. Answer
    Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 17 Apr 2009 Link to this post

    Hello Gerbrand,

    You can try using BeginUpdate/EndUpdate methods of GridElement:

    radGridView.GridElement.BeginUpdate(); 
     
    rgvAdlPositions.MasterGridViewTemplate.Rows.Add(new object[] { item.Adserver_id, item.Name });  
    var template = rgvAdlPositions.MasterGridViewTemplate.ChildGridViewTemplates[0];  
    foreach(var position in item.Positions)  
    {  
        Application.DoEvents();  
        //get the method as string  
        var method = Enums.GetMethod(position.Method);  
        //add to row  
        template.Rows.Add(new object[]  
                              {  
                                  item.Adserver_id, position.PosId,  
                                  ownFunctions.ConcatStrings(new List<string>  
                                                                          {  
                                                                              position.Name,  
                                                                              position.Width.ToString(),  
                                                                              "x",  
                                                                              position.Height.ToString()  
                                                                          }),  
                                  method  
                              });  
        var templateAd = template.ChildGridViewTemplates[0];  
        foreach(var adPos in position.adserverPositions)  
        {  
            //add adserved position to row  
            templateAd.Rows.Add(new object[] { item.Adserver_id, position.PosId, adPos.name });  
        }  
    }  
     
    radGridView.GridElement.EndUpdate(); 

    I hope this helps. If you have additional questions, feel free to contact me.

    Greetings,
    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. UI for WinForms is Visual Studio 2017 Ready
Back to Top