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)
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Reflection;
35 namespace System.Windows.Forms
37 public class AutoCompleteStringCollection : IList, ICollection, IEnumerable
39 private ArrayList list = null;
41 public AutoCompleteStringCollection ()
43 list = new ArrayList ();
46 public event CollectionChangeEventHandler CollectionChanged;
48 protected void OnCollectionChanged (CollectionChangeEventArgs e)
50 if(CollectionChanged == null)
53 CollectionChanged (this, e);
56 #region IEnumerable Members
58 public IEnumerator GetEnumerator ()
60 return list.GetEnumerator ();
65 #region ICollection Members
67 void ICollection.CopyTo (Array array, int index)
69 list.CopyTo (array, index);
72 public void CopyTo (string[] array, int index)
74 list.CopyTo (array, index);
79 get { return list.Count; }
82 public bool IsSynchronized
87 public object SyncRoot
96 int IList.Add (object value)
98 return Add ((string)value);
101 public int Add (string value)
103 int index = list.Add (value);
104 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
108 public void AddRange (string[] value)
111 throw new ArgumentNullException ("value", "Argument cannot be null!");
113 list.AddRange (value);
114 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
120 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
123 bool IList.Contains (object value)
125 return Contains ((string)value);
128 public bool Contains (string value)
130 return list.Contains (value);
133 int IList.IndexOf (object value)
135 return IndexOf ((string)value);
138 public int IndexOf (string value)
140 return list.IndexOf (value);
143 void IList.Insert (int index, object value)
145 Insert (index, (string)value);
148 public void Insert (int index, string value)
150 list.Insert (index, value);
151 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
154 bool IList.IsFixedSize
156 get { return false; }
159 bool IList.IsReadOnly
161 get { return false; }
164 public bool IsReadOnly
166 get { return false; }
169 void IList.Remove (object value)
171 Remove((string)value);
174 public void Remove (string value)
177 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
180 public void RemoveAt (int index)
182 string value = this[index];
183 list.RemoveAt (index);
184 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, value));
187 object IList.this[int index]
189 get { return this[index]; }
190 set { this[index] = (string)value; }
193 public string this[int index]
195 get { return (string)list[index]; }
197 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Remove, list[index]));
199 OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));