GridItemCollection.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2005 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jonathan Chambers ([email protected])
  24. //
  25. // COMPLETE
  26. using System;
  27. using System.Collections;
  28. namespace System.Windows.Forms
  29. {
  30. public class GridItemCollection : IEnumerable
  31. {
  32. #region Local Variables
  33. private System.Collections.SortedList list;
  34. #endregion // Local Variables
  35. #region Public Static Fields
  36. public static GridItemCollection Empty = new GridItemCollection();
  37. #endregion // Public Static Fields
  38. #region Constructors
  39. internal GridItemCollection()
  40. {
  41. list = new SortedList();
  42. }
  43. #endregion // Constructors
  44. #region Internal Properties and Methods
  45. internal void Add(string key, GridItem grid_item)
  46. {
  47. list.Add(key,grid_item);
  48. }
  49. #endregion // Internal Properties and Methods
  50. #region Public Instance Properties
  51. public int Count
  52. {
  53. get {
  54. return list.Count;
  55. }
  56. }
  57. public GridItem this [int index]
  58. {
  59. get {
  60. if (index>=list.Count) {
  61. throw new ArgumentOutOfRangeException("index");
  62. }
  63. return (GridItem)list.GetByIndex(index);
  64. }
  65. }
  66. public GridItem this [string key]
  67. {
  68. get {
  69. return (GridItem)list[key];
  70. }
  71. }
  72. #endregion // Public Instance Properties
  73. #region IEnumerable Members
  74. public IEnumerator GetEnumerator()
  75. {
  76. return new GridItemEnumerator(this);
  77. }
  78. #endregion
  79. #region Enumerator Class
  80. public class GridItemEnumerator : IEnumerator{
  81. int nIndex;
  82. GridItemCollection collection;
  83. public GridItemEnumerator(GridItemCollection coll) {
  84. collection = coll;
  85. nIndex = -1;
  86. }
  87. public bool MoveNext() {
  88. nIndex++;
  89. return(nIndex < collection.Count);
  90. }
  91. public void Reset() {
  92. nIndex = -1;
  93. }
  94. object System.Collections.IEnumerator.Current {
  95. get {
  96. return(collection[nIndex]);
  97. }
  98. }
  99. }
  100. #endregion
  101. }
  102. }