RadListBox Slow to load

4 posts, 0 answers
  1. Vijay
    Vijay avatar
    8 posts
    Member since:
    Oct 2007

    Posted 16 Jul 2008 Link to this post

    Hello,

    I have been using a radlistbox in my form and trying to display image against each record. the problem is that it takes around 7 seconds to display around 2000 records, which is very slow. in one of the article i have read that RadListBox take less than one second to load 2000 records
    I am using following lineof code to add the text and image to list.


    foreach (string strConnectedItem in arrTemp)

    {

    RadListBoxItem item = new RadListBoxItem();

    if (arrConnectedDLD.Count != 0 && arrConnectedDLD.Contains(strConnectedItem))

    {

    //arrConnectedDLDinMasterFile.Add(strConnectedItem);

    ////RadListBoxItem item = new RadListBoxItem();

    item.Text = strConnectedItem;

    item.Image = imageListLB.Images[1]; ;

    item.Value = strConnectedItem;

    arrDLDList.Add(strConnectedItem +

    "." + "1");

    radLbDLD.Items.Add(item);

    radCbDLD.Items.Add(

    new RadComboBoxItem(strConnectedItem, strConnectedItem));

    }

    else

    {

    // arrNotConnectedDLD.Add(strConnectedItem);

    //RadListBoxItem item = new RadListBoxItem();

    item.Text = strConnectedItem;

    item.Image = imageListLB.Images[0];

    item.Value = strConnectedItem;

    arrDLDList.Add(strConnectedItem +

    "." + "0");

    radLbDLD.Items.Add(item);

    radCbDLD.Items.Add(

    new RadComboBoxItem(strConnectedItem, strConnectedItem));

    }

    item.BorderThickness =

    new System.Windows.Forms.Padding(1);

    item.CanFocus =

    true;

    //item.Margin = new System.Windows.Forms.Padding(15, 0, 0, 0);

    item.TextImageRelation = System.Windows.Forms.

    TextImageRelation.ImageBeforeText;

    item.TextSeparatorVisibility = Telerik.WinControls.

    ElementVisibility.Visible;

    }


    if is remove the above code and instead use

    radLbDLD.DataSource = arrDLDList;


    then the loading time is reduced but inage is not displayed.
    as per my understanding the most of the time is taken in adding item to list on by one.
    is there any way by which I can avoid this looping.

    Also I could not find any property in RadListBox equivalent to ListBox.Items[n].ImageIndex in .net controls
    please suggest what can be done to improve the performance.

    Thanks & Regards,
    Vijay Chowdhary
  2. Angel
    Admin
    Angel avatar
    121 posts

    Posted 18 Jul 2008 Link to this post

    Hi Vijay,

    Up to the point:

    1. Speed

    There is a KB article that gives tips for optimizing RadComboBox and RadListBox performance.
    Here are some advices for making listbox and combobox faster:
    1. Call BeginUpdate() before and EndUpdate() after the loop for both the listbox and the combobox.
       
    2. Setting dependency properties is very slow and this is exactly what you are doing in the loop.
      Set as few as possible dependency properties.

    See below an example which is much faster than your code:

    radLbDLD.BeginUpdate();  
    radCbDLD.BeginUpdate();  
    for (int i = 0; i < arrTemp.Count; i++)  
    {  
        string strConnectedItem = arrTemp[i];  
     
        RadListBoxItem item = new RadListBoxItem();  
        if (arrConnectedDLD.Count != 0 && arrConnectedDLD.Contains(strConnectedItem))  
        {  
            item.Text = strConnectedItem;  
            item.ImageIndex = 1;  
            item.Value = strConnectedItem;  
            arrDLDList.Add(strConnectedItem + "." + "1");  
     
            radLbDLD.Items.Add(item);  
            radCbDLD.Items.Add(new RadComboBoxItem(strConnectedItem, strConnectedItem));  
        }  
        else  
        {  
            item.Text = strConnectedItem;  
            item.ImageIndex = 0;  
            item.Value = strConnectedItem;  
            arrDLDList.Add(strConnectedItem + "." + "0");  
     
            radLbDLD.Items.Add(item);  
            radCbDLD.Items.Add(new RadComboBoxItem(strConnectedItem, strConnectedItem));  
        }  
     
        //item.BorderThickness = new System.Windows.Forms.Padding(1);  
        //item.CanFocus = true;  
     
        item.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;  
        //item.TextSeparatorVisibility = Telerik.WinControls.ElementVisibility.Visible;  
    }  
    radCbDLD.EndUpdate();  
    radLbDLD.EndUpdate(); 

    We plan to introduce data items that are without dependency properties in some of our future releases.

    The reported time for 2000 items is for creating items with text only.
    Here is a demo loop with high speed:

    radLbDLD.BeginUpdate();  
    radCbDLD.BeginUpdate();  
    for (int i = 0; i < arrTemp.Count; i++)  
    {  
        string strConnectedItem = arrTemp[i];  
     
        radLbDLD.Items.Add(new RadListBoxItem(strConnectedItem));  
        radCbDLD.Items.Add(new RadComboBoxItem(strConnectedItem));  
    }  
    radCbDLD.EndUpdate();  
    radLbDLD.EndUpdate(); 


    2. ImageIndex property


    There are ImageIndex properties in both RadListBoxItem and RadComboBoxItem.
    The Items collection of RadListBox and RadComboBox contains a base type (RadItem) in order to allow any type of items to be added. So, a cast is necessary to access ImageIndex:

    RadListBoxItem itemToSet = radLbDLD.Items[0] as RadListBoxItem;
    if (itemToSet != null)
        itemToSet.ImageIndex = 0;


    Since you have the items in the loop, you can also set their ImageIndex directly:

    item.ImageIndex = 0;


    3. Binding

    There is an event during data binding, which can be used to customize each bound item - the ItemDataBound event.
    For more information see the section DataBinding for RadComboBox in the RadControls documentation.
    In the online help it can be found here.

    Greetings,

    Angel
    the Telerik team


    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. JustinWong
    JustinWong avatar
    147 posts
    Member since:
    Mar 2007

    Posted 17 Feb 2009 Link to this post

    Hi Angel:

    I'm just starting to use RadControls for WinForm and I'm concerned about the speed issue. Even if I place a RadDropDownbox with NOTHING in it (just a blank box), the page still takes between 1 and 2 seconds to load. If I take out the RadDropDownBox and just leave my standard WinForm controls in it, the page loads instanteously.

    Why is that the case? What will happend to load speed if I have a number of RadControls on the form?
  5. Nick
    Admin
    Nick avatar
    767 posts

    Posted 19 Feb 2009 Link to this post

    Hi JustinWong,

    Thank you for contacting us. I guess you mean RadComboBox control. I tested this with the latest versions, but I cannot reproduce such slow speeds. Could you send us a sample project? You can do so in a new support ticket. Also, make sure that you use the latest version of our controls. You can download it from our website (Q3 2008 SP2).

    Microsoft controls are expected to be faster since most of them are wrappers of unmanaged code and do not provide the features that Telerik controls provide, nor do they offer themes and animations. We always try to provide an acceptable performance level though. 

    I am looking forward to your sample application.  

    All the best,
    Nick
    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.
Back to Top