------解决方案-------------------- using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;
namespace NewApp { class AutoComplete { List<TextBox> _CompleteObjectList = new List<TextBox>(); Dictionary<string, AutoCompleteStringCollection> _Source = new Dictionary<string, AutoCompleteStringCollection>(); SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=TestDB;Integrated Security=True"); public AutoComplete() { conn.Open(); SqlCommand cmd = new SqlCommand("select * from AutoComplete", conn); SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { string key = read["name"].ToString(); if (!_Source.ContainsKey(key)) _Source.Add(key, new AutoCompleteStringCollection()); _Source[key].Add(read["str"].ToString()); } read.Close(); conn.Close(); }
public void AddAll(Control item) { for (int i = 0; i < item.Controls.Count; i++) { Control var = item.Controls[i]; if (var.GetType().Equals(typeof(TextBox))) { Add(var as TextBox); } } }
public void Add(TextBox text) { _CompleteObjectList.Add(text); text.Leave += new EventHandler(text_Leave); text.AutoCompleteMode = AutoCompleteMode.SuggestAppend; text.AutoCompleteSource = AutoCompleteSource.CustomSource; if (!_Source.ContainsKey(text.Name)) { _Source.Add(text.Name, new AutoCompleteStringCollection()); } text.AutoCompleteCustomSource = _Source[text.Name]; }
public void Delete(TextBox text) { _CompleteObjectList.Remove(text); }
public void DeleteAll(Control item) { for (int i = 0; i < item.Controls.Count; i++) { Control var = item.Controls[i]; if (var.GetType().Equals(typeof(TextBox))) { Delete(var as TextBox);