TableCellCollection.cs 4.0 KB

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