Home Forums WinForms controls Xceed Grid for WinForms Auto complete on combo boxes Reply To: Auto complete on combo boxes

User (Old forums)
Post count: 23064

I got some auto complete functions working by hacking up some code that was avaiable.

so far seems to work ok.
also set

Dim GridComboBox2 As EEC.Custom.Windows.Forms.GridCompletionComboBox = New EEC.Custom.Windows.Forms.GridCompletionComboBox

GridComboBox2.DropDownStyle = ComboBoxStyle.DropDown

just make a new library file from the following
//Copied from Genghis.Windows.Forms.CompletionCombo
//Modified for use with Xceed gridcombobox

using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using Xceed.Grid;
using Xceed.Grid.Editors;

namespace EEC.Custom.Windows.Forms
/// <summary>
/// Combo Box that should do an autocomplete when typing.
/// </summary>
public class GridCompletionComboBox : GridComboBox
public event System.ComponentModel.CancelEventHandler NotInList;

public bool LimitToList
get {return _limitToList;}
set { _limitToList = value;}

protected virtual void OnNotInList(System.ComponentModel.CancelEventArgs e)
if (NotInList != null)
NotInList.Invoke(this, e);

protected override void OnValidating(System.ComponentModel.CancelEventArgs e)
if (_limitToList)
int pos = FindStringExact(Text);
if (pos == -1)
this.SelectedIndex = pos;

protected override void OnKeyDown(KeyEventArgs args)
_autoComplete = args.KeyCode != Keys.Delete && args.KeyCode != Keys.Back;

protected override void OnTextChanged(EventArgs args)
string textEntered = Text;
int index = FindString(textEntered);
if (index >= 0 )
_autoComplete = false;
SelectedIndex = index;
_autoComplete = true;
Select(textEntered.Length, Text.Length);
private bool _autoComplete = true;
private bool _limitToList = true;

Imported from legacy forums. Posted by Vol (had 8014 views)