// This is the most timecritical part, adding items to the ListBox private void UpdateListBoxItems() { try { #region Excursus: DataSource vs. AddRange /* * // This part is not used due to 'listBox.DataSource' approach (see constructor) * // left for comparison, delete for productive use * listBox.BeginUpdate(); * listBox.Items.Clear(); * //Fills the ListBox * listBox.Items.AddRange(this.CurrentAutoCompleteList.ToArray()); * listBox.EndUpdate(); * // to use this method remove the following * // "((CurrencyManager)listBox.BindingContext[CurrentAutoCompleteList]).Refresh();" line and * // "listBox.DataSource = CurrentAutoCompleteList;" line from the constructor */ #endregion Excursus: DataSource vs. AddRange // if there is a TopLevelControl if ((TopLevelControl != null)) { _grid.Visible = GridView; listBox.Visible = !GridView; if (GridView) { _grid.BringToFront(); } else { _grid.SendToBack(); } // get its width panel.Width = this.Width + ExtraWidth + (GridView ? ExtraWidth_Pre : 0); // calculate the remeining height beneath the TextBox panel.Height = GetMyHeigh(); // ; // and the Location to use panel.Location = FindLocation(this) + new Size(0, this.Height); //this.Location + new Size(0, this.Height); // Panel and ListBox have to be added to TopLevelControl.Controls before calling BingingContext if (!this.TopLevelControl.Controls.Contains(panel)) { // add the Panel and ListBox to the PartenForm this.TopLevelControl.Controls.Add(panel); } // Update the listBox manually - List<string> dosn't support change events // this is the DataSource approche, this is a bit tricky and may cause conflicts, // so in case fall back to AddRange approache (see Excursus) if (!GridView) { ((CurrencyManager)listBox.BindingContext[CurrentAutoCompleteList]).Refresh(); } } } catch (Exception) { } }