Я исправил проблему, переключив setTimeout с
setTimeout(sayLetter(n-1), 1000);
на
setTimeout(function() { sayLetter(n-1), }, 1000);
Благодарность BFree для справки, но это - решение, которое я искал. ComboBox использует DataSet, поскольку это - источник, таким образом, это не пользовательский источник.
protected virtual void comboBoxAutoComplete_KeyPress(object sender, KeyPressEventArgs e) {
if (Char.IsControl(e.KeyChar)) {
//let it go if it's a control char such as escape, tab, backspace, enter...
return;
}
ComboBox box = ((ComboBox)sender);
//must get the selected portion only. Otherwise, we append the e.KeyChar to the AutoSuggested value (i.e. we'd never get anywhere)
string nonSelected = box.Text.Substring(0, box.Text.Length - box.SelectionLength);
string text = nonSelected + e.KeyChar;
bool matched = false;
for (int i = 0; i < box.Items.Count; i++) {
if (((DataRowView)box.Items[i])[box.DisplayMember].ToString().StartsWith(text, true, null)) {
matched = true;
break;
}
}
//toggle the matched bool because if we set handled to true, it precent's input, and we don't want to prevent
//input if it's matched.
e.Handled = !matched;
}
Хорошо, вот то, что я придумал. Взлом? Возможно, но эй, это работает. Я просто заполнил поле комбинированного списка днями недели (эй, мне было нужно что-то), и затем обработайте событие нажатия клавиши. На каждом нажатии клавиши я проверяю, соответствует ли то слово началу какого-либо слова в AutoCompleteSourceCollection. Если это не делает, я установил e. Обработанный к истинному, таким образом, ключ не становится зарегистрированным.
public Form5()
{
InitializeComponent();
foreach (var e in Enum.GetValues(typeof(DayOfWeek)))
{
this.comboBox1.AutoCompleteCustomSource.Add(e.ToString());
}
this.comboBox1.KeyPress += new KeyPressEventHandler(comboBox1_KeyPress);
}
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string text = this.comboBox1.Text + e.KeyChar;
e.Handled = !(this.comboBox1.AutoCompleteCustomSource.Cast<string>()
.Any(s => s.ToUpperInvariant().StartsWith(text.ToUpperInvariant()))) && !char.IsControl(e.KeyChar);
}
Править: Если Вы будете на.Net 3.5, то необходимо будет сослаться на Систему. Linq. Если Вы находитесь на.NET 2.0 затем использование это вместо этого:
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string text = this.comboBox1.Text + e.KeyChar;
foreach (string s in this.comboBox1.AutoCompleteCustomSource)
{
if (s.ToUpperInvariant().StartsWith(text.ToUpperInvariant()))
{
return;
}
}
e.Handled = true;
}