我正在我的 Windows 窗体应用程序中实现一个与 Google 一样工作的搜索功能。我已经实现了自动完成,如下所示:
private void MemberSearch()
{
// Name Search
ConnectionClass.GetInstance().connection_string = Properties.Settings.Default.MindMuscleConnectionString;
ConnectionClass.GetInstance().Sql = "select MemberInfo.memberName from MemberInfo";
DataSet ds = ConnectionClass.GetInstance().GetConnection;
AutoCompleteStringCollection name = new AutoCompleteStringCollection();
for (int x = 0; x < ds.Tables[0].Rows.Count; x++)
{
name.Add(ds.Tables[0].Rows[x].ItemArray.GetValue(0).ToString());
}
memberNameSearchTxtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
memberNameSearchTxtBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
memberNameSearchTxtBox.AutoCompleteCustomSource = name;
// ID Search
ConnectionClass.GetInstance().Sql = "select MemberInfo.memberID from MemberInfo";
ds = ConnectionClass.GetInstance().GetConnection;
AutoCompleteStringCollection id = new AutoCompleteStringCollection();
for (int x = 0; x < ds.Tables[0].Rows.Count; x++)
{
id.Add(ds.Tables[0].Rows[x].ItemArray.GetValue(0).ToString());
}
memberIdSearchTxtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
memberIdSearchTxtBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
memberIdSearchTxtBox.AutoCompleteCustomSource = id;
}
问题:
虽然这种自动完成工作得很好,但我在想如果记录的数量在数百万或更多,这种方法能正常工作吗?我在表单Load
事件上调用此方法。有没有更有效的方法来做到这一点?