yangyin
2025-02-28 baa80d650adebcce70f1113cc1020c6039c159a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//---------------------------------------------------------------------
// 
//  Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Controls
{
    public class TreeGridNodeCollection : System.Collections.Generic.IList<TreeGridNode>, System.Collections.IList
    {
        internal System.Collections.Generic.List<TreeGridNode> _list;
        internal TreeGridNode _owner;
        internal TreeGridNodeCollection(TreeGridNode owner)
        {
            this._owner = owner;
            this._list = new List<TreeGridNode>();
        }
 
        #region Public Members
        public void Add(TreeGridNode item)
        {
            // The row needs to exist in the child collection before the parent is notified.
            item._grid = this._owner._grid;
 
            bool hadChildren = this._owner.HasChildren;
            item._owner = this;
 
            this._list.Add(item);
 
            this._owner.AddChildNode(item);
 
            // if the owner didn't have children but now does (asserted) and it is sited update it
            if (!hadChildren && this._owner.IsSited)
            {
                this._owner._grid.InvalidateRow(this._owner.RowIndex);
            }
        }
 
        public TreeGridNode Add(string text)
        {
            TreeGridNode node = new TreeGridNode();
            this.Add(node);
 
            node.Cells[0].Value = text;
            return node;
        }
 
        public TreeGridNode Add(params object[] values)
        {
            TreeGridNode node = new TreeGridNode();
            this.Add(node);
 
            int cell = 0;
 
            if (values.Length > node.Cells.Count )
                throw new ArgumentOutOfRangeException("values");
 
            foreach (object o in values)
            {
                node.Cells[cell].Value = o;
                cell++;
            }
            return node;
        }
 
        public void Insert(int index, TreeGridNode item)
        {
            // The row needs to exist in the child collection before the parent is notified.
            item._grid = this._owner._grid;
            item._owner = this;
 
            this._list.Insert(index, item);
 
            this._owner.InsertChildNode(index, item);
        }
 
        public bool Remove(TreeGridNode item)
        {
            // The parent is notified first then the row is removed from the child collection.
            this._owner.RemoveChildNode(item);
            item._grid = null;
            return this._list.Remove(item);
        }
 
        public void RemoveAt(int index)
        {
            TreeGridNode row = this._list[index];
 
            // The parent is notified first then the row is removed from the child collection.
            this._owner.RemoveChildNode(row);
            row._grid = null;
            this._list.RemoveAt(index);
        }
 
        public void Clear()
        {
            // The parent is notified first then the row is removed from the child collection.
            this._owner.ClearNodes();
            this._list.Clear();
        }
 
        public int IndexOf(TreeGridNode item)
        {
            return this._list.IndexOf(item);
        }
 
        public TreeGridNode this[int index]
        {
            get
            {
                return this._list[index];
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }
 
        public bool Contains(TreeGridNode item)
        {
            return this._list.Contains(item);
        }
 
        public void CopyTo(TreeGridNode[] array, int arrayIndex)
        {
            throw new Exception("The method or operation is not implemented.");
        }
 
        public int Count
        {
            get{ return this._list.Count; }
        }
 
        public bool IsReadOnly
        {
            get{ return false; }
        }
        #endregion
 
        #region IList Interface
        void System.Collections.IList.Remove(object value)
        {
            this.Remove(value as TreeGridNode);
        }
 
 
        int System.Collections.IList.Add(object value)
        {
            TreeGridNode item = value as TreeGridNode;
            this.Add(item);
            return item.Index;
        }
 
        void System.Collections.IList.RemoveAt(int index)
        {
            this.RemoveAt(index);
        }
 
 
        void System.Collections.IList.Clear()
        {
            this.Clear();
        }
 
        bool System.Collections.IList.IsReadOnly
        {
            get { return this.IsReadOnly;}
        }
 
        bool System.Collections.IList.IsFixedSize
        {
            get { return false; }
        }
 
        int System.Collections.IList.IndexOf(object item)
        {
            return this.IndexOf(item as TreeGridNode);
        }
 
        void System.Collections.IList.Insert(int index, object value)
        {
            this.Insert(index, value as TreeGridNode);
        }
        int System.Collections.ICollection.Count
        {
            get { return this.Count; }
        }
        bool System.Collections.IList.Contains(object value)
        {
            return this.Contains(value as TreeGridNode);
        }
        void System.Collections.ICollection.CopyTo(Array array, int index)
        {
            throw new Exception("The method or operation is not implemented.");
        }
        object System.Collections.IList.this[int index]
        {
            get
            {
                return this[index];
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }
 
 
 
        #region IEnumerable<ExpandableRow> Members
 
        public IEnumerator<TreeGridNode> GetEnumerator()
        {
            return this._list.GetEnumerator();
        }
 
        #endregion
 
 
        #region IEnumerable Members
 
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
 
        #endregion
        #endregion
 
        #region ICollection Members
 
        bool System.Collections.ICollection.IsSynchronized
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }
 
        object System.Collections.ICollection.SyncRoot
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }
 
        #endregion
    }
 
}