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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
23 // Ravindra (rkumar@novell.com)
24 // Mike Kestner <mkestner@novell.com>
25 // Daniel Nauck (dna(at)mono-project(dot)de)
27 using System.Collections;
28 using System.ComponentModel;
30 using System.Runtime.Serialization;
32 namespace System.Windows.Forms
34 [DefaultProperty ("Text")]
35 [DesignTimeVisible (false)]
38 [TypeConverter (typeof (ListViewItemConverter))]
39 public class ListViewItem : ICloneable, ISerializable
41 #region Instance Variables
42 private int image_index = -1;
43 private bool is_checked = false;
44 private bool is_focused = false;
45 private int state_image_index = -1;
46 private ListViewSubItemCollection sub_items;
48 private bool use_item_style = true;
50 private ListViewGroup group = null;
51 private string name = String.Empty;
52 private string image_key = String.Empty;
53 int index; // cached index for VirtualMode
56 Rectangle checkbox_rect; // calculated by CalcListViewItem method
67 #endregion Instance Variables
69 #region Public Constructors
70 public ListViewItem ()
72 this.sub_items = new ListViewSubItemCollection (this);
73 this.sub_items.Add ("");
76 public ListViewItem (string text) : this (text, -1)
80 public ListViewItem (string [] items) : this (items, -1)
84 public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
86 this.sub_items = new ListViewSubItemCollection (this);
87 this.sub_items.AddRange (subItems);
88 this.image_index = imageIndex;
91 public ListViewItem (string text, int imageIndex)
93 this.image_index = imageIndex;
94 this.sub_items = new ListViewSubItemCollection (this);
95 this.sub_items.Add (text);
98 public ListViewItem (string [] items, int imageIndex)
100 this.sub_items = new ListViewSubItemCollection (this);
101 foreach (string item in items) // Don't use AddRange, since we need to add null strings
102 sub_items.Add (item);
103 this.image_index = imageIndex;
106 public ListViewItem (string [] items, int imageIndex, Color foreColor,
107 Color backColor, Font font)
109 this.sub_items = new ListViewSubItemCollection (this);
110 foreach (string item in items)
111 sub_items.Add (item);
112 this.image_index = imageIndex;
113 ForeColor = foreColor;
114 BackColor = backColor;
119 public ListViewItem(string[] items, string imageKey) : this(items)
121 this.ImageKey = imageKey;
124 public ListViewItem(string text, string imageKey) : this(text)
126 this.ImageKey = imageKey;
129 public ListViewItem(ListViewSubItem[] subItems, string imageKey) : this()
131 this.sub_items.AddRange(subItems);
132 this.ImageKey = imageKey;
135 public ListViewItem(string[] items, string imageKey, Color foreColor,
136 Color backColor, Font font) : this()
138 this.sub_items = new ListViewSubItemCollection(this);
139 foreach (string item in items)
140 sub_items.Add (item);
141 ForeColor = foreColor;
142 BackColor = backColor;
144 this.ImageKey = imageKey;
147 public ListViewItem(ListViewGroup group) : this()
152 public ListViewItem(string text, ListViewGroup group) : this(text)
157 public ListViewItem(string[] items, ListViewGroup group) : this(items)
162 public ListViewItem(ListViewSubItem[] subItems, int imageIndex, ListViewGroup group)
163 : this(subItems, imageIndex)
168 public ListViewItem(ListViewSubItem[] subItems, string imageKey, ListViewGroup group)
169 : this(subItems, imageKey)
174 public ListViewItem(string text, int imageIndex, ListViewGroup group)
175 : this(text, imageIndex)
180 public ListViewItem(string text, string imageKey, ListViewGroup group)
181 : this(text, imageKey)
186 public ListViewItem(string[] items, int imageIndex, ListViewGroup group)
187 : this(items, imageIndex)
192 public ListViewItem(string[] items, string imageKey, ListViewGroup group)
193 : this(items, imageKey)
198 public ListViewItem(string[] items, int imageIndex, Color foreColor, Color backColor,
199 Font font, ListViewGroup group)
200 : this(items, imageIndex, foreColor, backColor, font)
205 public ListViewItem(string[] items, string imageKey, Color foreColor, Color backColor,
206 Font font, ListViewGroup group)
207 : this(items, imageKey, foreColor, backColor, font)
212 #endregion // Public Constructors
214 #region Public Instance Properties
215 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
216 public Color BackColor {
218 if (sub_items.Count > 0)
219 return sub_items[0].BackColor;
222 return owner.BackColor;
224 return ThemeEngine.Current.ColorWindow;
227 set { sub_items[0].BackColor = value; }
231 public Rectangle Bounds {
233 return GetBounds (ItemBoundsPortion.Entire);
237 [DefaultValue (false)]
238 [RefreshProperties (RefreshProperties.Repaint)]
239 public bool Checked {
240 get { return is_checked; }
242 if (is_checked == value)
246 CheckState current_value = is_checked ? CheckState.Checked : CheckState.Unchecked;
247 CheckState new_value = value ? CheckState.Checked : CheckState.Unchecked;
249 ItemCheckEventArgs icea = new ItemCheckEventArgs (Index,
250 new_value, current_value);
251 owner.OnItemCheck (icea);
253 if (new_value != current_value) {
254 // force re-population of list
255 owner.CheckedItems.Reset ();
256 is_checked = new_value == CheckState.Checked;
260 ItemCheckedEventArgs args = new ItemCheckedEventArgs (this);
261 owner.OnItemChecked (args);
270 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
271 public bool Focused {
272 get { return is_focused; }
274 if (is_focused == value)
287 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
292 else if (owner != null)
295 return ThemeEngine.Current.DefaultFont;
309 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
310 public Color ForeColor {
312 if (sub_items.Count > 0)
313 return sub_items[0].ForeColor;
316 return owner.ForeColor;
318 return ThemeEngine.Current.ColorWindowText;
320 set { sub_items[0].ForeColor = value; }
324 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
325 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
326 typeof (System.Drawing.Design.UITypeEditor))]
329 [RefreshProperties (RefreshProperties.Repaint)]
330 // [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
332 [TypeConverter (typeof (ImageIndexConverter))]
334 public int ImageIndex {
335 get { return image_index; }
338 throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
342 image_key = String.Empty;
353 [LocalizableAttribute (true)]
354 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
355 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
356 typeof (System.Drawing.Design.UITypeEditor))]
357 [RefreshProperties (RefreshProperties.Repaint)]
358 // XXX [TypeConverter (typeof (ImageKeyConverter))
359 public string ImageKey {
364 image_key = value == null ? String.Empty : value;
375 public ImageList ImageList {
379 else if (owner.View == View.LargeIcon)
380 return owner.large_image_list;
382 return owner.small_image_list;
392 if (owner.VirtualMode)
396 return owner.Items.IndexOf (this);
401 public ListView ListView {
402 get { return owner; }
408 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
414 name = value == null ? String.Empty : value;
420 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
421 public bool Selected {
426 if (selected == value)
430 if (value && !owner.MultiSelect)
431 owner.SelectedItems.Clear ();
433 // force re-population of list
434 owner.SelectedIndices.Reset ();
436 owner.OnSelectedIndexChanged ();
445 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
446 typeof (System.Drawing.Design.UITypeEditor))]
449 [RefreshProperties (RefreshProperties.Repaint)]
450 // XXX [RelatedImageListAttribute ("ListView.StateImageList")]
451 // XXX [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
453 [TypeConverter (typeof (ImageIndexConverter))]
455 public int StateImageIndex {
456 get { return state_image_index; }
458 if (value < -1 || value > 14)
459 throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
461 state_image_index = value;
465 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
467 [Editor ("System.Windows.Forms.Design.ListViewSubItemCollectionEditor, " + Consts.AssemblySystem_Design,
468 typeof (System.Drawing.Design.UITypeEditor))]
470 public ListViewSubItemCollection SubItems {
471 get { return sub_items; }
475 [DefaultValue (null)]
476 [Localizable (false)]
477 [TypeConverter (typeof (StringConverter))]
484 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
487 if (this.sub_items.Count > 0)
488 return this.sub_items [0].Text;
493 if (sub_items [0].Text == value)
496 sub_items [0].Text = value;
504 [DefaultValue (true)]
505 public bool UseItemStyleForSubItems {
506 get { return use_item_style; }
507 set { use_item_style = value; }
511 [LocalizableAttribute(true)]
512 [DefaultValue (null)]
513 public ListViewGroup Group {
514 get { return this.group; }
517 if (this.group != value)
521 value.Items.Add(this);
523 if (this.group != null)
524 this.group.Items.Remove(this);
530 if(this.group != null)
531 this.group.Items.Remove(this);
538 #endregion // Public Instance Properties
540 #region Public Instance Methods
541 public void BeginEdit ()
543 if (owner != null && owner.LabelEdit) {
544 owner.item_control.BeginEdit (this);
547 // if (owner != null && owner.LabelEdit
548 // && owner.Activation == ItemActivation.Standard)
551 // throw new InvalidOperationException ();
554 public virtual object Clone ()
556 ListViewItem clone = new ListViewItem ();
557 clone.image_index = this.image_index;
558 clone.is_checked = this.is_checked;
559 clone.is_focused = this.is_focused;
560 clone.selected = this.selected;
561 clone.font = this.font;
562 clone.state_image_index = this.state_image_index;
563 clone.sub_items = new ListViewSubItemCollection (this);
565 foreach (ListViewSubItem subItem in this.sub_items)
566 clone.sub_items.Add (subItem.Text, subItem.ForeColor,
567 subItem.BackColor, subItem.Font);
568 clone.tag = this.tag;
569 clone.use_item_style = this.use_item_style;
578 public virtual void EnsureVisible ()
580 if (this.owner != null) {
581 owner.EnsureVisible (owner.Items.IndexOf (this));
585 public Rectangle GetBounds (ItemBoundsPortion portion)
588 return Rectangle.Empty;
593 case ItemBoundsPortion.Icon:
597 case ItemBoundsPortion.Label:
601 case ItemBoundsPortion.ItemOnly:
605 case ItemBoundsPortion.Entire:
610 throw new ArgumentException ("Invalid value for portion.");
613 Point item_loc = owner.GetItemLocation (Index);
614 rect.X += item_loc.X;
615 rect.Y += item_loc.Y;
619 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
624 public virtual void Remove ()
629 owner.item_control.CancelEdit (this);
630 owner.Items.Remove (this);
634 public override string ToString ()
636 return string.Format ("ListViewItem: {0}", this.Text);
638 #endregion // Public Instance Methods
640 #region Protected Methods
641 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
646 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
650 #endregion // Protected Methods
652 #region Private Internal Methods
653 internal Rectangle CheckRectReal {
655 Rectangle rect = checkbox_rect;
656 Point item_loc = owner.GetItemLocation (Index);
657 rect.X += item_loc.X;
658 rect.Y += item_loc.Y;
663 Rectangle text_bounds;
664 internal Rectangle TextBounds {
666 Rectangle result = text_bounds;
667 Point loc = owner.GetItemLocation (Index);
674 internal ListView Owner {
684 internal void SetIndex (int index)
690 internal void Invalidate ()
692 if (owner == null || owner.item_control == null)
695 owner.item_control.Invalidate (Bounds);
698 internal void Layout ()
702 Size text_size = owner.text_size;
704 checkbox_rect = Rectangle.Empty;
705 if (owner.CheckBoxes)
706 checkbox_rect.Size = owner.CheckBoxSize;
708 switch (owner.View) {
710 // LAMESPEC: MSDN says, "In all views except the details
711 // view of the ListView, this value specifies the same
712 // bounding rectangle as the Entire value." Actually, it
713 // returns same bounding rectangles for Item and Entire
714 // values in the case of Details view.
716 icon_rect = label_rect = Rectangle.Empty;
717 icon_rect.X = checkbox_rect.Width + 2;
718 item_ht = owner.ItemSize.Height;
720 if (owner.SmallImageList != null)
721 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
723 label_rect.Height = icon_rect.Height = item_ht;
724 checkbox_rect.Y = item_ht - checkbox_rect.Height;
726 label_rect.X = icon_rect.Right + 1;
728 if (owner.Columns.Count > 0)
729 label_rect.Width = owner.Columns [0].Wd - label_rect.X;
731 label_rect.Width = text_size.Width;
733 SizeF text_sz = owner.DeviceContext.MeasureString (Text, Font);
734 text_bounds = label_rect;
735 text_bounds.Width = (int) text_sz.Width;
737 item_rect = total = Rectangle.Union
738 (Rectangle.Union (checkbox_rect, icon_rect), label_rect);
739 bounds.Size = total.Size;
741 // Take into account the rest of columns. First column
742 // is already taken into account above.
743 for (int i = 1; i < owner.Columns.Count; i++) {
744 item_rect.Width += owner.Columns [i].Wd;
745 bounds.Width += owner.Columns [i].Wd;
750 label_rect = icon_rect = Rectangle.Empty;
752 SizeF sz = owner.DeviceContext.MeasureString (Text, Font);
753 if ((int) sz.Width > text_size.Width) {
755 int text_width = text_size.Width;
756 StringFormat format = new StringFormat ();
757 format.Alignment = StringAlignment.Center;
758 sz = owner.DeviceContext.MeasureString (Text, Font, text_width, format);
759 text_size.Height = (int) sz.Height;
761 text_size.Height = 2 * (int) sz.Height;
764 if (owner.LargeImageList != null) {
765 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
766 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
769 if (checkbox_rect.Height > icon_rect.Height)
770 icon_rect.Y = checkbox_rect.Height - icon_rect.Height;
772 checkbox_rect.Y = icon_rect.Height - checkbox_rect.Height;
774 if (text_size.Width <= icon_rect.Width) {
775 icon_rect.X = checkbox_rect.Width + 1;
776 label_rect.X = icon_rect.X + (icon_rect.Width - text_size.Width) / 2;
777 label_rect.Y = icon_rect.Bottom + 2;
778 label_rect.Size = text_size;
780 int centerX = text_size.Width / 2;
781 icon_rect.X = checkbox_rect.Width + 1 + centerX - icon_rect.Width / 2;
782 label_rect.X = checkbox_rect.Width + 1;
783 label_rect.Y = icon_rect.Bottom + 2;
784 label_rect.Size = text_size;
787 item_rect = Rectangle.Union (icon_rect, label_rect);
788 total = Rectangle.Union (item_rect, checkbox_rect);
789 bounds.Size = total.Size;
794 label_rect = icon_rect = Rectangle.Empty;
795 icon_rect.X = checkbox_rect.Width + 1;
796 item_ht = Math.Max (owner.CheckBoxSize.Height, text_size.Height);
798 if (owner.SmallImageList != null) {
799 item_ht = Math.Max (item_ht, owner.SmallImageList.ImageSize.Height);
800 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
801 icon_rect.Height = owner.SmallImageList.ImageSize.Height;
804 checkbox_rect.Y = item_ht - checkbox_rect.Height;
805 label_rect.X = icon_rect.Right + 1;
806 label_rect.Width = text_size.Width;
807 label_rect.Height = icon_rect.Height = item_ht;
809 item_rect = Rectangle.Union (icon_rect, label_rect);
810 total = Rectangle.Union (item_rect, checkbox_rect);
811 bounds.Size = total.Size;
815 label_rect = icon_rect = Rectangle.Empty;
817 if (owner.LargeImageList != null) {
818 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
819 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
823 SizeF tsize = owner.DeviceContext.MeasureString (Text, Font);
825 // Set initial values for subitem's layout
826 int total_height = (int)Math.Ceiling (tsize.Height);
827 int max_subitem_width = (int)Math.Ceiling (tsize.Width);
828 SubItems [0].bounds.Height = total_height;
830 int count = Math.Min (owner.Columns.Count, SubItems.Count);
831 for (int i = 1; i < count; i++) { // Ignore first column and first subitem
832 ListViewSubItem sub_item = SubItems [i];
833 if (sub_item.Text == null || sub_item.Text.Length == 0)
836 tsize = owner.DeviceContext.MeasureString (sub_item.Text, sub_item.Font);
838 int width = (int)Math.Ceiling (tsize.Width);
840 if (width > max_subitem_width)
841 max_subitem_width = width;
843 int height = (int)Math.Ceiling (tsize.Height);
844 total_height += height + separation;
846 sub_item.bounds.Height = height;
850 label_rect.X = icon_rect.Right + 4;
851 label_rect.Y = owner.TileSize.Height / 2 - total_height / 2;
852 label_rect.Width = max_subitem_width;
853 label_rect.Height = total_height;
855 // Second pass for assigning bounds. This time take first subitem into account.
856 int current_y = label_rect.Y;
857 for (int j = 0; j < count; j++) {
858 ListViewSubItem sub_item = SubItems [j];
859 if (sub_item.Text == null || sub_item.Text.Length == 0)
862 sub_item.SetBounds (label_rect.X, current_y, max_subitem_width, sub_item.bounds.Height);
863 current_y += sub_item.Bounds.Height + separation;
866 item_rect = Rectangle.Union (icon_rect, label_rect);
867 bounds.Size = item_rect.Size;
873 #endregion // Private Internal Methods
877 [DefaultProperty ("Text")]
878 [DesignTimeVisible (false)]
880 [ToolboxItem (false)]
881 [TypeConverter (typeof(ListViewSubItemConverter))]
882 public class ListViewSubItem
884 private Color back_color;
886 private Color fore_color;
887 internal ListViewItem owner;
888 private string text = string.Empty;
890 private string name = String.Empty;
892 internal Rectangle bounds;
895 #region Public Constructors
896 public ListViewSubItem ()
900 public ListViewSubItem (ListViewItem owner, string text)
901 : this (owner, text, Color.Empty,
906 public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
907 Color backColor, Font font)
911 this.fore_color = foreColor;
912 this.back_color = backColor;
915 #endregion // Public Constructors
917 #region Public Instance Properties
918 public Color BackColor {
920 if (this.back_color != Color.Empty)
921 return this.back_color;
922 if (this.owner != null && this.owner.ListView != null)
923 return this.owner.ListView.BackColor;
924 return ThemeEngine.Current.ColorWindow;
933 public Rectangle Bounds {
935 Rectangle retval = bounds;
937 retval.X += owner.Bounds.X;
938 retval.Y += owner.Bounds.Y;
951 else if (owner != null)
953 return ThemeEngine.Current.DefaultFont;
963 public Color ForeColor {
965 if (this.fore_color != Color.Empty)
966 return this.fore_color;
967 if (this.owner != null && this.owner.ListView != null)
968 return this.owner.ListView.ForeColor;
969 return ThemeEngine.Current.ColorWindowText;
984 name = value == null ? String.Empty : value;
988 [TypeConverter (typeof (StringConverter))]
989 [BindableAttribute (true)]
990 [DefaultValue (null)]
991 [Localizable (false)]
1002 [Localizable (true)]
1003 public string Text {
1004 get { return text; }
1010 text = string.Empty;
1017 #endregion // Public Instance Properties
1019 #region Public Methods
1020 public void ResetStyle ()
1022 font = ThemeEngine.Current.DefaultFont;
1023 back_color = ThemeEngine.Current.DefaultControlBackColor;
1024 fore_color = ThemeEngine.Current.DefaultControlForeColor;
1028 public override string ToString ()
1030 return string.Format ("ListViewSubItem {{0}}", text);
1032 #endregion // Public Methods
1035 #region Private Methods
1036 private void Invalidate ()
1038 if (owner == null || owner.owner == null)
1041 owner.owner.Invalidate ();
1045 internal int Height {
1047 return bounds.Height;
1051 internal void SetBounds (int x, int y, int width, int height)
1053 bounds = new Rectangle (x, y, width, height);
1056 #endregion // Private Methods
1059 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
1061 private ArrayList list;
1062 internal ListViewItem owner;
1064 #region Public Constructors
1065 public ListViewSubItemCollection (ListViewItem owner)
1068 this.list = new ArrayList ();
1070 #endregion // Public Constructors
1072 #region Public Properties
1075 get { return list.Count; }
1078 public bool IsReadOnly {
1079 get { return false; }
1082 public ListViewSubItem this [int index] {
1083 get { return (ListViewSubItem) list [index]; }
1085 value.owner = this.owner;
1086 list [index] = value;
1091 public virtual ListViewSubItem this [string key] {
1093 int idx = IndexOfKey (key);
1097 return (ListViewSubItem) list [idx];
1102 bool ICollection.IsSynchronized {
1103 get { return list.IsSynchronized; }
1106 object ICollection.SyncRoot {
1107 get { return list.SyncRoot; }
1110 bool IList.IsFixedSize {
1111 get { return list.IsFixedSize; }
1114 object IList.this [int index] {
1115 get { return this [index]; }
1117 if (! (value is ListViewSubItem))
1118 throw new ArgumentException ("Not of type ListViewSubItem", "value");
1119 this [index] = (ListViewSubItem) value;
1122 #endregion // Public Properties
1124 #region Public Methods
1125 public ListViewSubItem Add (ListViewSubItem item)
1127 item.owner = this.owner;
1132 public ListViewSubItem Add (string text)
1134 ListViewSubItem item = new ListViewSubItem (this.owner, text);
1139 public ListViewSubItem Add (string text, Color foreColor,
1140 Color backColor, Font font)
1142 ListViewSubItem item = new ListViewSubItem (this.owner, text,
1143 foreColor, backColor, font);
1148 public void AddRange (ListViewSubItem [] items)
1151 throw new ArgumentNullException ("items");
1153 foreach (ListViewSubItem item in items) {
1160 public void AddRange (string [] items)
1163 throw new ArgumentNullException ("items");
1165 foreach (string item in items) {
1172 public void AddRange (string [] items, Color foreColor,
1173 Color backColor, Font font)
1176 throw new ArgumentNullException ("items");
1178 foreach (string item in items) {
1181 this.Add (item, foreColor, backColor, font);
1185 public void Clear ()
1190 public bool Contains (ListViewSubItem item)
1192 return list.Contains (item);
1196 public virtual bool ContainsKey (string key)
1198 return IndexOfKey (key) != -1;
1202 public IEnumerator GetEnumerator ()
1204 return list.GetEnumerator ();
1207 void ICollection.CopyTo (Array dest, int index)
1209 list.CopyTo (dest, index);
1212 int IList.Add (object item)
1214 if (! (item is ListViewSubItem)) {
1215 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1218 ListViewSubItem sub_item = (ListViewSubItem) item;
1219 sub_item.owner = this.owner;
1220 return list.Add (sub_item);
1223 bool IList.Contains (object subItem)
1225 if (! (subItem is ListViewSubItem)) {
1226 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1229 return this.Contains ((ListViewSubItem) subItem);
1232 int IList.IndexOf (object subItem)
1234 if (! (subItem is ListViewSubItem)) {
1235 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1238 return this.IndexOf ((ListViewSubItem) subItem);
1241 void IList.Insert (int index, object item)
1243 if (! (item is ListViewSubItem)) {
1244 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1247 this.Insert (index, (ListViewSubItem) item);
1250 void IList.Remove (object item)
1252 if (! (item is ListViewSubItem)) {
1253 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1256 this.Remove ((ListViewSubItem) item);
1259 public int IndexOf (ListViewSubItem subItem)
1261 return list.IndexOf (subItem);
1265 public virtual int IndexOfKey (string key)
1267 if (key == null || key.Length == 0)
1270 for (int i = 0; i < list.Count; i++) {
1271 ListViewSubItem l = (ListViewSubItem) list [i];
1272 if (String.Compare (l.Name, key, true) == 0)
1280 public void Insert (int index, ListViewSubItem item)
1282 item.owner = this.owner;
1283 list.Insert (index, item);
1286 public void Remove (ListViewSubItem item)
1292 public virtual void RemoveByKey (string key)
1294 int idx = IndexOfKey (key);
1300 public void RemoveAt (int index)
1302 list.RemoveAt (index);
1304 #endregion // Public Methods
1306 #endregion // Subclasses