TableRowCollection.cs 2.7 KB

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