2 // AutoCompleteStringCollection.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Daniel Nauck
26 // Daniel Nauck (dna(at)mono-project(dot)de)
30 using System.Collections;
31 using System.ComponentModel;
32 using System.Reflection;
34 namespace System.Windows.Forms
36 public class AutoCompleteStringCollection : IList, ICollection, IEnumerable
38 private ArrayList list = null;
40 public AutoCompleteStringCollection ()
42 list = new ArrayList ();
45 public event CollectionChangeEventHandler CollectionChanged;
47 protected void OnCollectionChanged (CollectionChangeEventArgs e)
49 if(CollectionChanged == null)
52 CollectionChanged (this, e);
55 #region IEnumerable Members
57 public IEnumerator GetEnumerator ()
59 return list.GetEnumerator ();
64 #region ICollection Members
66 void ICollection.CopyTo (Array array, int index)
68 list.CopyTo (array, index);
71 public void CopyTo (string[] array, int index)
73 list.CopyTo (array, index);
78 get { return list.Count; }
81 public bool IsSynchronized
86 public object SyncRoot
95 int IList.Add (object value)
97 return Add ((string)value);
100 public int Add (string value)
102 int index = list.Add (value);
103 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
107 public void AddRange (string[] value)
110 throw new ArgumentNullException ("value", "Argument cannot be null!");
112 list.AddRange (value);
113 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
119 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
122 bool IList.Contains (object value)
124 return Contains ((string)value);
127 public bool Contains (string value)
129 return list.Contains (value);
132 int IList.IndexOf (object value)
134 return IndexOf ((string)value);
137 public int IndexOf (string value)
139 return list.IndexOf (value);
142 void IList.Insert (int index, object value)
144 Insert (index, (string)value);
147 public void Insert (int index, string value)
149 list.Insert (index, value);
150 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
153 bool IList.IsFixedSize
155 get { return false; }
158 bool IList.IsReadOnly
160 get { return false; }
163 public bool IsReadOnly
165 get { return false; }
168 void IList.Remove (object value)
170 Remove((string)value);
173 public void Remove (string value)
176 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
179 public void RemoveAt (int index)
181 string value = this[index];
182 list.RemoveAt (index);
183 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
186 object IList.this[int index]
188 get { return this[index]; }
189 set { this[index] = (string)value; }
192 public string this[int index]
194 get { return (string)list[index]; }
196 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, list[index]));
198 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));