1 // 2 // System.Web.UI.WebControls.TableRowCollection.cs 3 // 4 // Author: 5 // Sebastien Pouliot <sebastien@ximian.com> 6 // 7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com) 8 // 9 // Permission is hereby granted, free of charge, to any person obtaining 10 // a copy of this software and associated documentation files (the 11 // "Software"), to deal in the Software without restriction, including 12 // without limitation the rights to use, copy, modify, merge, publish, 13 // distribute, sublicense, and/or sell copies of the Software, and to 14 // permit persons to whom the Software is furnished to do so, subject to 15 // the following conditions: 16 // 17 // The above copyright notice and this permission notice shall be 18 // included in all copies or substantial portions of the Software. 19 // 20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 // 28 29 using System.ComponentModel; 30 using System.Collections; 31 32 namespace System.Web.UI.WebControls { 33 34 [Editor ("System.Web.UI.Design.WebControls.TableRowsCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)] 35 public sealed class TableRowCollection : IList, ICollection, IEnumerable 36 { 37 ControlCollection cc; 38 Table owner; 39 TableRowCollection(Table table)40 internal TableRowCollection (Table table) 41 { 42 if (table == null) 43 throw new ArgumentNullException ("table"); 44 45 cc = table.Controls; 46 owner = table; 47 } 48 49 public int Count { 50 get { return cc.Count; } 51 } 52 53 public bool IsReadOnly { 54 get { return false; } // documented as always false 55 } 56 57 public bool IsSynchronized { 58 get { return false; } // documented as always false 59 } 60 61 public TableRow this [int index] { 62 get { return (TableRow) cc [index]; } 63 } 64 65 public object SyncRoot { 66 get { return this; } // as documented 67 } 68 Add(TableRow row)69 public int Add (TableRow row) 70 { 71 if (row == null) 72 throw new NullReferenceException (); // .NET compatibility 73 if (row.TableRowSectionSet) 74 owner.GenerateTableSections = true; 75 row.Container = this; 76 int index = cc.IndexOf (row); 77 if (index < 0) { 78 cc.Add (row); 79 index = cc.Count; 80 } 81 return index; 82 } 83 AddAt(int index, TableRow row)84 public void AddAt (int index, TableRow row) 85 { 86 if (row == null) 87 throw new NullReferenceException (); // .NET compatibility 88 89 if (cc.IndexOf (row) < 0) { 90 if (row.TableRowSectionSet) 91 owner.GenerateTableSections = true; 92 row.Container = this; 93 cc.AddAt (index, row); 94 } 95 } 96 AddRange(TableRow[] rows)97 public void AddRange (TableRow[] rows) 98 { 99 foreach (TableRow tr in rows) { 100 if (tr == null) 101 throw new NullReferenceException (); // .NET compatibility 102 103 if (cc.IndexOf (tr) < 0) { 104 if (tr.TableRowSectionSet) 105 owner.GenerateTableSections = true; 106 tr.Container = this; 107 cc.Add (tr); 108 } 109 } 110 } 111 Clear()112 public void Clear () 113 { 114 owner.GenerateTableSections = false; 115 cc.Clear (); 116 } 117 CopyTo(Array array, int index)118 public void CopyTo (Array array, int index) 119 { 120 cc.CopyTo (array, index); 121 } 122 GetEnumerator()123 public IEnumerator GetEnumerator () 124 { 125 return cc.GetEnumerator (); 126 } 127 GetRowIndex(TableRow row)128 public int GetRowIndex (TableRow row) 129 { 130 return cc.IndexOf (row); 131 } 132 RowTableSectionSet()133 internal void RowTableSectionSet () 134 { 135 owner.GenerateTableSections = true; 136 } 137 Remove(TableRow row)138 public void Remove (TableRow row) 139 { 140 if (row != null) 141 row.Container = null; 142 cc.Remove (row); 143 } 144 RemoveAt(int index)145 public void RemoveAt (int index) 146 { 147 TableRow row = this [index] as TableRow; 148 if (row != null) 149 row.Container = null; 150 151 cc.RemoveAt (index); 152 } 153 154 155 // implements IList but doesn't make some members public 156 157 bool IList.IsFixedSize { 158 get { return false; } 159 } 160 161 object IList.this [int index] { 162 get { return cc [index]; } 163 set { 164 cc.AddAt (index, (TableRow)value); 165 cc.RemoveAt (index + 1); 166 } 167 } 168 169 IList.Add(object value)170 int IList.Add (object value) 171 { 172 return Add (value as TableRow); 173 } 174 IList.Contains(object value)175 bool IList.Contains (object value) 176 { 177 return cc.Contains (value as TableRow); 178 } 179 IList.IndexOf(object value)180 int IList.IndexOf (object value) 181 { 182 return cc.IndexOf (value as TableRow); 183 } 184 IList.Insert(int index, object value)185 void IList.Insert (int index, object value) 186 { 187 AddAt (index, value as TableRow); 188 } 189 IList.Remove(object value)190 void IList.Remove (object value) 191 { 192 Remove (value as TableRow); 193 } 194 } 195 } 196