TableCellCollection.cs 2.7 KB

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