How to improve Listbox performance in ADO.NET 2.0?

I have a bunch of listboxes on my windows forms with a couple of thousand records in each one of them. It takes almost about a minute to load a form in .NET 1.1 We are migrating the application to .NET 2.0 and was wondering if there is any way to improve the performance in ADO.NET 2.0 so that the listboxes are loaded faster in .NET 2.0

I tried running speed test as per:

http://msdn.microsoft.com/msdnmag/issues/05/11/DataPoints/default.aspx fig=true#fig6

and was really satisfied with the promising results.

Please let me know if you have general tips / suggestions to improve performance of ADO.NET Windows Forms Application in general. I have already read a bunch of articles that came up through a simple google search but was wondering if someone has already worked on something similar.

Thanks

csharpkid@gmail.com



Answer this question

How to improve Listbox performance in ADO.NET 2.0?

  • Hassano

    In 1.1 we were directly binding the listbox / combobox to a field in the datatable to add the items.

    E.g. If I have a combobox that lists all the departments, such that RequestDoD table contains the foreign key (Department_ID) to a corresponding record in Department table then I would be doing something like:
    private void SetBindings(DSDoD dsDoD, int rwIndex)
    {
    _cm = (CurrencyManager) this.BindingContext[dsDoD, "RequestDoD"];
    _cm.Position = rwIndex;
    _drv = ((DataRowView) _cm.Current).Row;
    if(_drv["ID"] != DBNull.Value)
    {
    cboDepartmentID.DataSource = _dsDoD.PersonnelDepartment;
    cboDepartmentID.DisplayMember = "Department";
    cboDepartmentID.ValueMember = "ID";
    cboDepartmentID.DataBindings.Add("SelectedValue", _dsDoD, " RequestDOD.Department_ID");
    .....
    .....
    }
    }
    Then I would call SetBindings( ) before loading my form to ensure that the Department combobox is loaded with all the values. This works perfect when we are dealing with a small number of records but as soon as it starts going above a thousand records or so, you would start experiencing delays when you have a bunch of comboboxes on the same form.
    The tables in this case would be populated with simple stored proc calls which would have statements like 'Select Department from Department'. If I run them in SQA they don't take that long to load and that's what makes me think that something might be wrong with the way I am binding my comboboxes.

  • JMakitalo

    I don't have that much experience with databinding to say if you do anything incorrect or that it could be done better..

    You can check out the forum for databinding if you have not already done it.

    http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=7&SiteID=1



  • Keldon Alleyne

    I used a simple thread(Thread Class) seems to be fine. I tried loading 10,000 entries to a listview using a separate thread using an XMLdocument as the datasource. I can see the listview being filled, but the listview and the window is responsive. I think this will be fine for a combobox since the control initially starts as collapsed.
  • Alexander M.

    I would not call it to fake better user experience. If the user gets a better experience and the job done, what is fake about it

    I could imagine a few things you could do to load up the items at startup and give a better user experience than taking a minute to display it. However I have no clue how you are adding the items so my ideas might be useless for you.

    If you are using Add() and add each item individually I would check consider building up my own array of items and then using AddRange() to add them all at once to the control.

    Load the items asynchron, the form will display quick but not all data will be there until finish loading the items.



  • Ben B

    Well, going back,.... a solution that I had already thought about, but I think it is really a 'work-around' and not a performance gain. A little bit disappointment considering other big improvements to ADO.NET 2.0.

    My earlier thoughts were not to load thousands of records into a listbox in the first place. As you have suggested this will not really help in performance but at least it would FAKE a better user experience which should be alright I guess.

    Thanks for your response anyway.


  • dotnetwiz

    I wonder how is this scenario implemented in Windows Media Player. Somehow the controls are populated really fast considering I have 10,000 songs in my library.
  • HoustonRocket

    Is it really a good idea to load thousands of records in a listbox isn't the UI supossed to be helpful for the user (I mean, if I were the user I wouldnt like to have a combobox with 10,000 things inside...imagine trying to find something inside that!... IMHO a better user experience is to allow the user to search what he is looking for (and only use comboxes for smaller lists with a maximum of 50 items)
    If you really want to provide a better user experience... perhaps you should be thinking on using a Tree... or several "nested" comboboxes...

  • CaptMcCrank

    My suggestion would be to not load thousand of items into a listbox. Start up the form empty and have a search functionality for the listbox that only loads up a subset of all entries, if the user enters some search criteria.

    This will not really help in performance but I would like better to work with an application like that. For me it increases the user experience.

    If a user interface is responsive and set the expectation that something can take long time users a less likely to complain about it. If a form would take as long as a minute to be displayed I would use task manager to kill it even before it would present it to me. I would not kill it if I initiate an action to search for thousand of records to populate a listbox.

    End result is basically the same but my experience of it would be totally different.



  • How to improve Listbox performance in ADO.NET 2.0?