1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Pedro MartÃnez Juliá <pedromj@gmail.com>
29 using System.ComponentModel;
30 using System.Collections;
32 namespace System.Windows.Forms {
34 [ListBindable (false)]
35 public class DataGridViewCellCollection : BaseCollection, IList, ICollection, IEnumerable {
37 private DataGridViewRow dataGridViewRow;
39 public DataGridViewCellCollection (DataGridViewRow dataGridViewRow) : base() {
40 this.dataGridViewRow = dataGridViewRow;
43 bool IList.IsFixedSize {
44 get { return base.List.IsFixedSize; }
47 object IList.this [int index] {
48 get { return this[index]; }
49 set { this[index] = value as DataGridViewCell; }
52 public DataGridViewCell this [int index] {
53 get { return (DataGridViewCell) base.List[index]; }
54 set { Insert(index, value); }
57 public DataGridViewCell this [string columnName] {
59 foreach (DataGridViewCell cell in base.List) {
60 if (cell.OwningColumn.Name == columnName) {
67 for (int i = 0; i < base.List.Count; i++) {
68 DataGridViewCell cell = (DataGridViewCell) base.List[i];
69 if (cell.OwningColumn.Name == columnName) {
78 public event CollectionChangeEventHandler CollectionChanged;
80 int IList.Add (object o) {
81 return Add(o as DataGridViewCell);
84 public virtual int Add (DataGridViewCell dataGridViewCell) {
85 dataGridViewCell.SetOwningRow(dataGridViewRow);
86 dataGridViewCell.SetColumnIndex(base.List.Count);
87 dataGridViewCell.SetDataGridView(dataGridViewRow.DataGridView);
88 int result = base.List.Add(dataGridViewCell);
89 OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, dataGridViewCell));
93 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
94 public virtual void AddRange (params DataGridViewCell[] dataGridViewCells) {
95 foreach (DataGridViewCell cell in dataGridViewCells) {
100 public virtual void Clear () {
104 bool IList.Contains (object o) {
105 return Contains(o as DataGridViewCell);
108 public virtual bool Contains (DataGridViewCell dataGridViewCell) {
109 return base.List.Contains(dataGridViewCell);
112 public void CopyTo (DataGridViewCell[] array, int index) {
113 base.List.CopyTo(array, index);
116 int IList.IndexOf (object o) {
117 return IndexOf(o as DataGridViewCell);
120 public int IndexOf (DataGridViewCell dataGridViewCell) {
121 return base.List.IndexOf(dataGridViewCell);
124 void IList.Insert (int index, object o) {
125 Insert(index, o as DataGridViewCell);
128 public virtual void Insert (int index, DataGridViewCell dataGridViewCell) {
129 dataGridViewCell.SetOwningRow(dataGridViewRow);
130 dataGridViewCell.SetColumnIndex(index);
131 dataGridViewCell.SetDataGridView(dataGridViewRow.DataGridView);
132 base.List.Insert(index, dataGridViewCell);
133 OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Add, dataGridViewCell));
136 void IList.Remove (object o) {
137 Remove(o as DataGridViewCell);
140 public virtual void Remove (DataGridViewCell dataGridViewCell) {
141 base.List.Remove(dataGridViewCell);
142 OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, dataGridViewCell));
145 public virtual void RemoveAt (int index) {
146 DataGridViewCell cell = this[index];
147 base.List.RemoveAt(index);
148 OnCollectionChanged(new CollectionChangeEventArgs(CollectionChangeAction.Remove, cell));
151 protected override ArrayList List {
152 get { return base.List; }
155 protected void OnCollectionChanged (CollectionChangeEventArgs e) {
156 if (CollectionChanged != null) {
157 CollectionChanged(this, e);