You'd think you'd do it just like the normal ComboBox
:
this.comboBox1.AutoCompleteCustomSource = new AutoCompleteStringCollection();
this.comboBox1.AutoCompleteCustomSource.AddRange(new string[] { "Good night", "Good evening", "Good", "All Good", "I'm Good" });
this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
With the expectant results:
As it turns out, you can! But the selected option won't persist once you leave the cell. I found you have to change how you add the drop-down options and how you source them:
public Form1()
{
InitializeComponent();
DataGridViewComboBoxColumn cc = new DataGridViewComboBoxColumn();
cc.Name = "Combo";
cc.Items.AddRange(new string[] { "Good night", "Good evening", "Good", "All Good", "I'm Good" });
this.dataGridView1.Columns.Add(cc);
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox box = e.Control as ComboBox;
if (box != null)
{
box.DropDownStyle = ComboBoxStyle.DropDown;
box.AutoCompleteSource = AutoCompleteSource.ListItems;
box.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
}
}
This will provide you the desired results:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…