BrightIdeasSoftware.ObjectListView.ConfigureAutoComplete C# (CSharp) Method

ConfigureAutoComplete() public method

Configure the given text box to autocomplete unique values from the given column. At most 1000 rows will be considered.
public ConfigureAutoComplete ( TextBox tb, OLVColumn column, int maxRows ) : void
tb System.Windows.Forms.TextBox The textbox to configure
column OLVColumn The column used to calculate values
maxRows int Consider only this many rows
return void
        public void ConfigureAutoComplete(TextBox tb, OLVColumn column, int maxRows)
        {
            // Don't consider more rows than we actually have
            maxRows = Math.Min(this.GetItemCount(), maxRows);

            // Reset any existing autocomplete
            tb.AutoCompleteCustomSource.Clear();

            // CONSIDER: Should we use ClusteringStrategy here?

            // Build a list of unique values, to be used as autocomplete on the editor
            Dictionary<string, bool> alreadySeen = new Dictionary<string, bool>();
            List<string> values = new List<string>();
            for (int i = 0; i < maxRows; i++) {
                string valueAsString = column.GetStringValue(this.GetModelObject(i));
                if (!String.IsNullOrEmpty(valueAsString) && !alreadySeen.ContainsKey(valueAsString)) {
                    values.Add(valueAsString);
                    alreadySeen[valueAsString] = true;
                }
            }

            tb.AutoCompleteCustomSource.AddRange(values.ToArray());
            tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
            tb.AutoCompleteMode = column.AutoCompleteEditorMode;
        }

Same methods

ObjectListView::ConfigureAutoComplete ( TextBox tb, OLVColumn column ) : void
ObjectListView