TableCellCollection.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: TableCellCollection
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.Collections;
  15. using System.Web;
  16. using System.Web.UI;
  17. using System.ComponentModel;
  18. namespace System.Web.UI.WebControls
  19. {
  20. //[Editor("??")]
  21. public sealed class TableCellCollection: IList, ICollection, IEnumerable
  22. {
  23. private TableRow owner;
  24. internal TableCellCollection(TableRow owner)
  25. {
  26. if(owner == null)
  27. {
  28. throw new ArgumentNullException();
  29. }
  30. this.owner = owner;
  31. }
  32. public int Count
  33. {
  34. get
  35. {
  36. return owner.Controls.Count;
  37. }
  38. }
  39. public bool IsReadOnly
  40. {
  41. get
  42. {
  43. return false;
  44. }
  45. }
  46. public bool IsSynchronized
  47. {
  48. get
  49. {
  50. return false;
  51. }
  52. }
  53. public TableCell this[int index]
  54. {
  55. get
  56. {
  57. return (TableCell)owner.Controls[index];
  58. }
  59. }
  60. public object SyncRoot
  61. {
  62. get
  63. {
  64. return this;
  65. }
  66. }
  67. public int Add(TableCell cell)
  68. {
  69. AddAt(-1, cell);
  70. return owner.Controls.Count;
  71. }
  72. public void AddAt(int index, TableCell cell)
  73. {
  74. owner.Controls.AddAt(index, cell);
  75. }
  76. public void AddRange(TableCell[] cells)
  77. {
  78. foreach(TableCell cell in cells)
  79. {
  80. Add(cell);
  81. }
  82. }
  83. public void Clear()
  84. {
  85. if(owner.HasControls())
  86. {
  87. owner.Controls.Clear();
  88. }
  89. }
  90. public void CopyTo(Array array, int index)
  91. {
  92. foreach(object cell in this)
  93. {
  94. array.SetValue(cell, index++);
  95. }
  96. }
  97. public int GetCellIndex(TableCell cell)
  98. {
  99. if(!owner.HasControls())
  100. {
  101. return -1;
  102. }
  103. return owner.Controls.IndexOf(cell);
  104. }
  105. public IEnumerator GetEnumerator()
  106. {
  107. return owner.Controls.GetEnumerator();
  108. }
  109. public void Remove(TableCell cell)
  110. {
  111. owner.Controls.Remove(cell);
  112. }
  113. public void RemoveAt(int index)
  114. {
  115. owner.Controls.RemoveAt(index);
  116. }
  117. int IList.Add(object o)
  118. {
  119. return Add((TableCell)o);
  120. }
  121. bool IList.Contains(object o)
  122. {
  123. return owner.Controls.Contains((TableCell)o);
  124. }
  125. int IList.IndexOf(object o)
  126. {
  127. return owner.Controls.IndexOf((TableCell)o);
  128. }
  129. void IList.Insert(int index, object o)
  130. {
  131. owner.Controls.AddAt(index, (TableCell)o);
  132. }
  133. void IList.Remove(object o)
  134. {
  135. owner.Controls.Remove((TableCell)o);
  136. }
  137. bool IList.IsFixedSize
  138. {
  139. get
  140. {
  141. return false;
  142. }
  143. }
  144. object IList.this[int index]
  145. {
  146. get
  147. {
  148. return this[index];
  149. }
  150. set
  151. {
  152. RemoveAt(index);
  153. AddAt(index, (TableCell)value);
  154. }
  155. }
  156. }
  157. }