Click here to Skip to main content
13,559,281 members
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 28 Jul 2011
Licenced CPOL

Loading huge data in a Silverlight AutoCompleteBox

, 9 Aug 2011
Rate this:
Please Sign up or sign in to vote.
Creating a custom AutoCompleteBox which will filter large amounts of data quickly.

Table of contents

  1. Introduction
  2. Prerequisites
  3. Modifying the AutoCompleteBox to load huge data
  4. Conclusion


AutoCompleteBox is a very useful control in Silverlight. It gives suggestions to the user based on input from the ItemsSource assigned to it. This control works fine when a limited number of items are added as ItemsSource; say a few thousands of entries. But if the items assigned to it grows after may be 20000+, the UI will hang and this would create a bad user experience.

For normal applications, huge data like this may not be expected but in a business application, this is a quite possible scenario. In one of my previous projects, I came across such a scenario. I resolved this by tweaking one of AutoCompleteBox’s properties (TextFilter) and it gave me a very good result. I would like to share this so that it will be useful to someone who has such a requirement in Silverlight.


This sample application is developed in VS-2010 Express edition and Silverlight 4. Please download them from Microsoft website if you don’t have them installed. I created the sample application using the Silverlight Navigation project.

Modifying AutoCompleteBox to load huge data

See the screenshot of the sample application:


Here, the page has an AutoCompleteBox from the SDK and it is getting loaded with 20,000 strings.

sourceList = new List<string>();
for (int i = 0; i < 20000; i++)
    sourceList.Add("Item-" + i);
this.acbSample.ItemsSource = sourceList;

If the user tries to type a letter, the AutoCompleteBox will not load data and the page will hang. Eventually, data will get loaded after sometime. This delay will increase with more data. This is because the control tries to load the entire entries and then tries to match the data. We can improve the loading performance if we can limit the number of items getting loaded in the dropdown of AutoCompleteBox. Setting the MaxDropDownHeight property will not help here as this will only limit the height of the dropdown and still the control will try to load everything. So I created a custom AutoCompleteBox with an AutoCompleteBox in the usercontrol. This is present in the FastLoadingACB library in the attached solution.

As you can see, in FastLoadingACB.xaml.cs, only the required properties are exposed as Dependency Properties (DP). I have exposed the Width and ItemsSource properties of AutoCompleteBox in the new user control. AutoCompleteBox’s SelectionChangedEvent is also exposed in the user control. A new DP called MaxItemsInDropDown is added in the user control to limit the number of items getting loaded in the AutoCompleteBox dropdown. The magic of limiting the number of items is achieved by modifying the AutoCompleteFilterPredicate<string> TextFilter property of the AutoCompleteBox. This property’s documentation from the metadata is “Gets or sets the custom method that uses the user-entered text to filter items specified by the System.Windows.Controls.AutoCompleteBox.ItemsSource property in a text-based way for display in the drop-down”. In AutoCompleteBox’s Loaded event, a new predicate is given for TextFilter, as shown below:

private void acbFastLoading_Loaded(object sender, RoutedEventArgs e)
    this.acbFastLoading.TextFilter = (search, value) =>
            if (value.Length > 0)
                if ((this.counter < MaxItemsInDropDown) &&
                    (value.ToUpper().StartsWith(search.ToUpper()) || 
                    return true;
                    return false;
                return false;

A private member counter is introduced which is set to 0 when AutoCompleteBox’s text changes as shown above. This will ensure that whenever the user types something, only the number of items mentioned in MaxItemsInDropDown will get populated in the dropdown. Now the new control is loaded with 200,000 strings; 10 times more than the previous case.

IList<string> sourceList = new List<string>();

for (int i = 0; i < 200000; i++)
    sourceList.Add("Item-" + i);

this.acbFastLoading.FastLoadingACBItemsSource = sourceList;

As you can see, the data gets filtered and loaded in the dropdown very quickly.



This approach is a simple way to improve the loading and filtering performance of an AutoCompleteBox. Any/all properties required by the consuming application should be exposed as a Dependency Property in the new user control created. This approach may not be required when the application loads small amounts of data but will be really useful if you are working with huge amounts data. Happy coding…


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Renil Joy, Bangalore
Software Developer (Senior) CA-CIB
Singapore Singapore
I am a .Net developer, currently working in Singapore worked wiith Societe Generale Global Solution Centre, Bangalore and was previously with Cognizant.I have more than 8 years of .Net experience in BFSI domain. I am an experienced developer in C#, VB.Net, Silverlight, WPF, WCF, LINQ, Entity Framework, SSIS, NHibernate, ASP.Net and SQL Server.

You may also be interested in...


Comments and Discussions

QuestionI'm confused. Isn't this getting the wrong results? Pin
mtiede19-Mar-15 8:29
membermtiede19-Mar-15 8:29 
AnswerRe: I'm confused. Isn't this getting the wrong results? Pin
Renil Joy, Bangalore19-Mar-15 13:56
memberRenil Joy, Bangalore19-Mar-15 13:56 
GeneralRe: I'm confused. Isn't this getting the wrong results? Pin
mtiede20-Mar-15 2:19
membermtiede20-Mar-15 2:19 
GeneralRe: I'm confused. Isn't this getting the wrong results? Pin
Renil Joy, Bangalore20-Mar-15 3:14
memberRenil Joy, Bangalore20-Mar-15 3:14 
SuggestionSlight Improvement in this solution Pin
microgold13-Aug-14 8:42
membermicrogold13-Aug-14 8:42 
GeneralRe: Slight Improvement in this solution Pin
Renil Joy, Bangalore19-Aug-14 15:57
memberRenil Joy, Bangalore19-Aug-14 15:57 
QuestionThanks Pin
TortNum4-Aug-14 3:01
memberTortNum4-Aug-14 3:01 
AnswerRe: Thanks Pin
Renil Joy, Bangalore4-Aug-14 14:53
memberRenil Joy, Bangalore4-Aug-14 14:53 
QuestionGetting ACB Text Value Pin
arunpalanisamy19-Aug-13 1:51
memberarunpalanisamy19-Aug-13 1:51 
QuestionHow to Get this autocomplete Box Text Value Pin
arunpalanisamy18-Aug-13 19:10
memberarunpalanisamy18-Aug-13 19:10 
QuestionVery Cool Pin
civiceng14-Mar-13 4:01
memberciviceng14-Mar-13 4:01 
AnswerRe: Very Cool Pin
Renil Joy, Bangalore21-Mar-13 8:20
memberRenil Joy, Bangalore21-Mar-13 8:20 
BugProblem downloading sample Pin
beffes27-Jun-12 22:26
memberbeffes27-Jun-12 22:26 
GeneralRe: Problem downloading sample Pin
Renil Joy, Bangalore29-Jun-12 13:53
memberRenil Joy, Bangalore29-Jun-12 13:53 
Questionlooks pretty good BUT Pin
john010118-Apr-12 2:56
memberjohn010118-Apr-12 2:56 
AnswerRe: looks pretty good BUT Pin
Renil Joy, Bangalore18-Apr-12 10:10
memberRenil Joy, Bangalore18-Apr-12 10:10 
SuggestionAwesome! Pin
jlester4229-Dec-11 17:09
memberjlester4229-Dec-11 17:09 
GeneralRe: Awesome! Pin
Renil Joy, Bangalore1-Jan-12 23:38
memberRenil Joy, Bangalore1-Jan-12 23:38 
QuestionBind to an object Pin
rrre_e23-Aug-11 21:18
memberrrre_e23-Aug-11 21:18 
AnswerRe: Bind to an object Pin
Renil Joy, Bangalore17-Sep-11 14:18
memberRenil Joy, Bangalore17-Sep-11 14:18 
QuestionAutoCompleteBox.Populating Pin
PaulLinton16-Aug-11 13:40
memberPaulLinton16-Aug-11 13:40 
AnswerRe: AutoCompleteBox.Populating Pin
Renil Joy, Bangalore17-Sep-11 14:23
memberRenil Joy, Bangalore17-Sep-11 14:23 
AnswerRe: AutoCompleteBox.Populating Pin
Drew Noakes21-Oct-11 1:38
memberDrew Noakes21-Oct-11 1:38 
GeneralMy vote of 5 Pin
Sunasara Imdadhusen9-Aug-11 17:38
memberSunasara Imdadhusen9-Aug-11 17:38 
GeneralRe: My vote of 5 Pin
Renil Joy, Bangalore13-Aug-11 7:28
memberRenil Joy, Bangalore13-Aug-11 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180515.1 | Last Updated 9 Aug 2011
Article Copyright 2011 by Renil Joy, Bangalore
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid