搜索建议API和自动完成文本框

时间:2017-05-22 15:22:51

标签: c#

我有一个类根据传递给它的文本返回 Google建议的列表。我的问题是:

  

如何使用此类作为文本框工具的AutoCompleteCustomSource工作,以便用户可以在其中编写文本,并将发送到此类的文本带到用户正在编写的建议列表中,并且用户添加的每个垃圾都将是添加到文本中会再次发送给课程以提出更多建议吗?

例如,对该课程的此次调用会根据" arduino "填写textbox1一份建议列表。字:

SearchSuggestionsAPI search = new SearchSuggestionsAPI();
IList result = (await search.GetSearchSuggestions("arduino"));
for (int i = 0; i < result.Count; i++)
{
    string sent = result[i].ToString();
    textBox1.AutoCompleteCustomSource.Add(result[i].ToString());
    textBox1.AppendText(sent);
    textBox1.AppendText(Environment.NewLine);
}

1 个答案:

答案 0 :(得分:0)

我没有尝试过,但这样的事情可能有用:

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    var results = (await search.GetSearchSuggestions(textBox1.Text));

    textBox1.AutoCompleteCustomSource.Clear();
    textBox1.AutoCompleteCustomSource.AddRange( results );
}