






















缓存内容,根据输入筛选结果
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Drawing;
5
using System.Data;
6
using System.Windows.Forms;
7
8
namespace NetBee.Infrastructure
9
{
10
/// <summary>
11
/// SuperComboBox 的摘要说明。
12
/// </summary>
13
public class SuperComboBox : System.Windows.Forms.ComboBox
14
{
15
/// <summary>
16
/// 必需的设计器变量。
17
/// </summary>
18
private System.ComponentModel.Container components = null;
19
20
private ArrayList _items=new ArrayList();
21
private string cache;
22
23
public SuperComboBox()
24
{
25
// 该调用是 Windows.Forms 窗体设计器所必需的。
26
InitializeComponent();
27
28
// TODO: 在 InitializeComponent 调用后添加任何初始化
29
}
30
31
public void AddItemIn()
32
{
33
if(this._items.Count>0)
34
{
35
if(!this._items.Contains(this.Text) && this.Text!="")
36
{
37
this._items.Add(this.Text);
38
}
39
}
40
else
41
{
42
if(this.Text!="")
43
{
44
this._items.Add(this.Text);
45
}
46
}
47
}
48
49
public int GetItemsCount()
50
{
51
return this._items.Count;
52
}
53
54
/// <summary>
55
/// 清理所有正在使用的资源。
56
/// </summary>
57
protected override void Dispose( bool disposing )
58
{
59
if( disposing )
60
{
61
if(components != null)
62
{
63
components.Dispose();
64
}
65
}
66
base.Dispose( disposing );
67
}
68
69
#region 组件设计器生成的代码
70
/// <summary>
71
/// 设计器支持所需的方法 - 不要使用代码编辑器
72
/// 修改此方法的内容。
73
/// </summary>
74
private void InitializeComponent()
75
{
76
//
77
// SuperComboBox
78
//
79
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.SuperComboBox_KeyPress);
80
this.TextChanged += new System.EventHandler(this.SuperComboBox_TextChanged);
81
82
}
83
#endregion
84
85
private void SuperComboBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
86
{
87
if(e.KeyChar=='\r')
88
{
89
this.DroppedDown=false;
90
this.Text=this.cache;
91
//this.DoSearch();
92
}
93
94
if(char.IsControl(e.KeyChar))
95
{
96
if(e.KeyChar=='\b')
97
{
98
this.DroppedDown=false;
99
this.Text=this.cache;
100
}
101
}
102
}
103
104
public void ShowList()
105
{
106
this.DroppedDown=true;
107
}
108
109
public void HideList()
110
{
111
this.DroppedDown=false;
112
}
113
114
public ArrayList GetFilteredList()
115
{
116
this.Items.Clear();
117
118
ArrayList newArrayList=new ArrayList();
119
newArrayList.Clear();
120
foreach(string str in this._items)
121
{
122
if(str.Length>0)
123
{
124
if(str.IndexOf(this.Text)==0 && (!str.Equals(this.Text)))
125
{
126
newArrayList.Add(str);
127
}
128
}
129
}
130
return newArrayList;
131
}
132
133
134
private void SuperComboBox_TextChanged(object sender, System.EventArgs e)
135
{
136
this.cache=this.Text;
137
if(this.Text!="")
138
{
139
object[] al=this.GetFilteredList().ToArray();
140
if(al.Length>0)
141
{
142
this.AddItemsCore(al);
143
this.ShowList();
144
if(this.cache!="")this.Text=this.cache;
145
this.SelectionStart=this.Text.Length+1;
146
}
147
else
148
{
149
if(this.DroppedDown==true)
150
{
151
this.HideList();
152
this.Focus();
153
this.SelectionStart=this.cache.Length;
154
}
155
else
156
{
157
this.SelectionStart=this.Text.Length+1;
158
}
159
}
160
}
161
162
}
163
}
164
}
165
Posted on 2005-05-22 22:05 RichardChoi 阅读(639) 评论(0) 收藏 举报
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。