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