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;
}