C#实现百度中的搜索框的下选效果!
来源:互联网 发布:网络直播如何互动 编辑:程序博客网 时间:2024/05/22 05:09
01.using System;
02.using System.Collections.Generic;
03.using System.Text;
04.using System.Windows.Forms;
05.using System.Data.SqlClient;
06.
07.namespace NewApp
08.{
09. class AutoComplete
10. {
11. List<TextBox> _CompleteObjectList = new List<TextBox>();
12. Dictionary<string, AutoCompleteStringCollection> _Source = new Dictionary<string, AutoCompleteStringCollection>();
13. SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=TestDB;Integrated Security=True");
14. public AutoComplete()
15. {
16. conn.Open();
17. SqlCommand cmd = new SqlCommand("select * from AutoComplete", conn);
18. SqlDataReader read = cmd.ExecuteReader();
19. while (read.Read())
20. {
21. string key = read["name"].ToString();
22. if (!_Source.ContainsKey(key))
23. _Source.Add(key, new AutoCompleteStringCollection());
24. _Source[key].Add(read["str"].ToString());
25. }
26. read.Close();
27. conn.Close();
28. }
29.
30. public void AddAll(Control item)
31. {
32. for (int i = 0; i < item.Controls.Count; i++)
33. {
34. Control var = item.Controls[i];
35. if (var.GetType().Equals(typeof(TextBox)))
36. {
37. Add(var as TextBox);
38. }
39. }
40. }
41.
42. public void Add(TextBox text)
43. {
44. _CompleteObjectList.Add(text);
45. text.Leave += new EventHandler(text_Leave);
46. text.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
47. text.AutoCompleteSource = AutoCompleteSource.CustomSource;
48. if (!_Source.ContainsKey(text.Name))
49. {
50. _Source.Add(text.Name, new AutoCompleteStringCollection());
51. }
52. text.AutoCompleteCustomSource = _Source[text.Name];
53. }
54.
55. public void Delete(TextBox text)
56. {
57. _CompleteObjectList.Remove(text);
58. }
59.
60. public void DeleteAll(Control item)
61. {
62. for (int i = 0; i < item.Controls.Count; i++)
63. {
64. Control var = item.Controls[i];
65. if (var.GetType().Equals(typeof(TextBox)))
66. {
67. Delete(var as TextBox);
68. }
69. }
70. }
71.
72. public void AutoCompleteClear()
73. {
74. foreach (AutoCompleteStringCollection var in _Source.Values)
75. { var.Clear(); }
76. SqlCommand cmd = new SqlCommand("Delete AutoComplete", conn);
77. conn.Open();
78. cmd.ExecuteNonQuery();
79. conn.Close();
80. }
81.
82. void text_Leave(object sender, EventArgs e)
83. {
84. TextBox text = sender as TextBox;
85. if (text.Text == "")
86. return;
87. string key = text.Name;
88. if (!_Source.ContainsKey(key))
89. {
90. _Source.Add(key, new AutoCompleteStringCollection());
91. }
92. if (!_Source[key].Contains(text.Text))
93. {
94. SqlCommand cmd = new SqlCommand("insert into AutoComplete select '" + key.Replace("'", "''") + "', '" + text.Text.Replace("'", "''") + "'", conn);
95. conn.Open();
96. cmd.ExecuteNonQuery();
97. _Source[key].Add(text.Text);
98. conn.Close();
99. }
100. }
101. }
102.}
- C#实现百度中的搜索框的下选效果!
- C#实现百度中的搜索框的下选效果!
- C#实现百度中的搜索框的下选效果!
- 实现百度搜索效果
- 实现百度搜索输入框效果
- 百度的搜索效果
- 基于Servlet百度搜索效果的Ajax的实现实例
- jquery百度搜索框的搜索效果插件
- ASP.NET实现百度分类搜索的效果
- asp实现Ajax百度搜索提示的效果
- Arcgis for Javascript API下类似于百度搜索A、B、C、D marker的实现方式
- jQuery JavaScript实现百度搜索下拉框效果
- 使用javascript ajax C#实现类似百度的搜索框效果
- 使用DWR实现自动补全 类似百度搜索框的自动显示效果
- JS实现输入框类似百度搜索的智能提示效果
- AJAX实现百度搜索栏效果
- js实现百度搜索结果翻页效果
- 百度搜索建议的实现
- 参考:大部分ADO错误代码对应含义说明
- VS2008数据导出EXCEL问题
- 【原创】彼得德鲁克《管理的实践》札记(三)
- short,int,long与byte数组之间的转换
- linux下网络工具之tcpdump
- C#实现百度中的搜索框的下选效果!
- flex_assql连接mysql
- 计算机类国外经典书籍
- linux内核调试指南
- c++ 注册表类
- C#winform中怎么将程序最小化到系统托盘
- 黑莓BES系统架构介绍
- 参考:ASP错误代码说明
- 终于开通自己的博客