여기서는 취할 수있는 한 가지 방법이 있습니다. 다음 코드는 3 자 이상을 입력 할 때 텍스트 상자의 TextChanged
이벤트에서 제안 사항을 가져옵니다. 우리는 제안을 얻은 다음 제안이 반환되었는지 확인합니다. 예인 경우 AutoCompleteCustomSource
을 설정합니다. 그렇지 않으면, 우리는 무엇을 하든지 할 것입니다.
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox t = sender as TextBox;
if (t != null)
{
// Here I am making the assumption we will get suggestions after
// 3 characters are entered
if (t.Text.Length >= 3)
{
// This will get the suggestions from some place like db,
// table etc.
string[] arr = GetSuggestions(t.Text);
if (arr.Length == 0) {// do whatever you want to}
else
{
var collection = new AutoCompleteStringCollection();
collection.AddRange(arr);
this.textBox1.AutoCompleteCustomSource = collection;
}
}
}
}