Note that there are some explanatory texts on larger screens.

plurals
  1. POAutocomplete Box - Inconsistent values from population
    text
    copied!<p>I have a WPF application with the autocomplete box via the toolkit (VS 2008). I have a potential population of about 2000 records and I have tried to improve performance with a combination of the populating event procedure. I am getting inconsistent results. The filter seems to be OK but I can run the app once and result X will be there but result Y wont. Running it again can make result Y be there and not X, subsequent times both X and Y will be there, etc, etc. This is my first time using the autocomplete box so I'm sure it must be something in my code that I'm forgetting. If I check my result set just prior to the Itemsource binding, the desired results are there, but they are not made visible to the user - the drop-down autocomplete back does not show. Maybe I need an event override???</p> <p><em><strong>The XAML</em></strong></p> <pre><code>&lt;input:AutoCompleteBox Name="autGlobal" FilterMode="Contains" Style="{DynamicResource MiniSearchAutoBoxWPF}" IsTextCompletionEnabled="false" Margin="5, 0, 5, 0" HorizontalAlignment="Center" KeyUp="autGlobal_KeyUp" Text="Search Term" GotFocus="autGlobal_GotFocus" ValueMemberPath="Item" Populating="AutoCompleteBox_Populating" &gt; </code></pre> <p><em><strong>The Methods</em></strong></p> <pre><code> private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e) { e.Cancel = true; var b = new BackgroundWorker(); currSearch = autGlobal.Text; b.DoWork += b_DoWork; b.RunWorkerCompleted += b_RunWorkerCompleted; b.RunWorkerAsync(autGlobal.Text); } private void b_DoWork(object sender, DoWorkEventArgs e) { Results.Clear(); int counter = 0; string search = e.Argument.ToString(); search = search.ToUpper(); foreach (GlobalSearchList person in myGlobalList) { if (person.Item.ToUpper().Contains(search)) { Results.Add(person); counter++; if (counter &gt;= MAX_NUM_OF_RESULTS) { break; } } } } private void b_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (this.Dispatcher.Thread == System.Threading.Thread.CurrentThread) { //Set the source if (currSearch == autGlobal.Text) { autGlobal.ItemsSource = Results; autGlobal.PopulateComplete(); } } else { this.Dispatcher.Invoke(new Action(() =&gt; { //Set the source if (currSearch == autGlobal.Text) { autGlobal.ItemsSource = Results; autGlobal.PopulateComplete(); } })); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload