TableRowCollection.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: TableRowCollection
  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.Web;
  15. using System.Collections;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. public sealed class TableRowCollection: IList, ICollection, IEnumerable
  20. {
  21. Table owner;
  22. internal TableRowCollection(Table 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 TableRow this[int index]
  52. {
  53. get
  54. {
  55. return (TableRow)owner.Controls[index];
  56. }
  57. }
  58. public object SyncRoot
  59. {
  60. get
  61. {
  62. return this;
  63. }
  64. }
  65. public int Add(TableRow row)
  66. {
  67. AddAt(-1, row);
  68. return owner.Controls.Count;
  69. }
  70. public void AddAt(int index, TableRow row)
  71. {
  72. owner.Controls.AddAt(index, row);
  73. }
  74. public void AddRange(TableRow[] rows)
  75. {
  76. foreach(TableRow row in rows)
  77. {
  78. Add(row);
  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 current in this)
  91. {
  92. array.SetValue(current, index++);
  93. }
  94. }
  95. public int GetRowIndex(TableRow row)
  96. {
  97. if(!owner.HasControls())
  98. {
  99. return -1;
  100. }
  101. return owner.Controls.IndexOf(row);
  102. }
  103. public IEnumerator GetEnumerator()
  104. {
  105. return owner.Controls.GetEnumerator();
  106. }
  107. public void Remove(TableRow row)
  108. {
  109. owner.Controls.Remove(row);
  110. }
  111. public void RemoveAt(int index)
  112. {
  113. owner.Controls.RemoveAt(index);
  114. }
  115. int IList.Add(object o)
  116. {
  117. return Add((TableRow)o);
  118. }
  119. bool IList.Contains(object o)
  120. {
  121. return owner.Controls.Contains((TableRow)o);
  122. }
  123. int IList.IndexOf(object o)
  124. {
  125. return owner.Controls.IndexOf((TableRow)o);
  126. }
  127. void IList.Insert(int index, object o)
  128. {
  129. owner.Controls.AddAt(index, (TableRow)o);
  130. }
  131. void IList.Remove(object o)
  132. {
  133. owner.Controls.Remove((TableRow)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, (TableRow)value);
  152. }
  153. }
  154. }
  155. }