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 () : this (string.Empty)
74 public ListViewItem (string text) : this (text, -1)
78 public ListViewItem (string [] items) : this (items, -1)
82 public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
84 this.sub_items = new ListViewSubItemCollection (this);
85 for (int i = 0; i < subItems.Length; i++)
86 sub_items.Add (subItems [i]);
87 this.image_index = imageIndex;
90 public ListViewItem (string text, int imageIndex)
92 this.image_index = imageIndex;
93 this.sub_items = new ListViewSubItemCollection (this);
94 this.sub_items.Add (text);
97 public ListViewItem (string [] items, int imageIndex)
99 this.sub_items = new ListViewSubItemCollection (this);
101 for (int i = 0; i < items.Length; i++)
102 sub_items.Add (new ListViewSubItem (this, items [i]));
104 this.image_index = imageIndex;
107 public ListViewItem (string [] items, int imageIndex, Color foreColor,
108 Color backColor, Font font) : this (items, imageIndex)
110 ForeColor = foreColor;
111 BackColor = backColor;
116 public ListViewItem(string[] items, string imageKey) : this(items)
118 this.ImageKey = imageKey;
121 public ListViewItem(string text, string imageKey) : this(text)
123 this.ImageKey = imageKey;
126 public ListViewItem(ListViewSubItem[] subItems, string imageKey)
128 this.sub_items = new ListViewSubItemCollection (this);
129 for (int i = 0; i < subItems.Length; i++)
130 this.sub_items.Add (subItems [i]);
131 this.ImageKey = imageKey;
134 public ListViewItem(string[] items, string imageKey, Color foreColor,
135 Color backColor, Font font) : this(items, imageKey)
137 ForeColor = foreColor;
138 BackColor = backColor;
142 public ListViewItem(ListViewGroup group) : this()
147 public ListViewItem(string text, ListViewGroup group) : this(text)
152 public ListViewItem(string[] items, ListViewGroup group) : this(items)
157 public ListViewItem(ListViewSubItem[] subItems, int imageIndex, ListViewGroup group)
158 : this(subItems, imageIndex)
163 public ListViewItem(ListViewSubItem[] subItems, string imageKey, ListViewGroup group)
164 : this(subItems, imageKey)
169 public ListViewItem(string text, int imageIndex, ListViewGroup group)
170 : this(text, imageIndex)
175 public ListViewItem(string text, string imageKey, ListViewGroup group)
176 : this(text, imageKey)
181 public ListViewItem(string[] items, int imageIndex, ListViewGroup group)
182 : this(items, imageIndex)
187 public ListViewItem(string[] items, string imageKey, ListViewGroup group)
188 : this(items, imageKey)
193 public ListViewItem(string[] items, int imageIndex, Color foreColor, Color backColor,
194 Font font, ListViewGroup group)
195 : this(items, imageIndex, foreColor, backColor, font)
200 public ListViewItem(string[] items, string imageKey, Color foreColor, Color backColor,
201 Font font, ListViewGroup group)
202 : this(items, imageKey, foreColor, backColor, font)
207 #endregion // Public Constructors
209 #region Public Instance Properties
210 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
211 public Color BackColor {
213 if (sub_items.Count > 0)
214 return sub_items[0].BackColor;
217 return owner.BackColor;
219 return ThemeEngine.Current.ColorWindow;
221 set { SubItems [0].BackColor = value; }
225 public Rectangle Bounds {
227 return GetBounds (ItemBoundsPortion.Entire);
231 [DefaultValue (false)]
232 [RefreshProperties (RefreshProperties.Repaint)]
233 public bool Checked {
234 get { return is_checked; }
236 if (is_checked == value)
240 CheckState current_value = is_checked ? CheckState.Checked : CheckState.Unchecked;
241 CheckState new_value = value ? CheckState.Checked : CheckState.Unchecked;
243 ItemCheckEventArgs icea = new ItemCheckEventArgs (Index,
244 new_value, current_value);
245 owner.OnItemCheck (icea);
247 if (new_value != current_value) {
248 // force re-population of list
249 owner.CheckedItems.Reset ();
250 is_checked = new_value == CheckState.Checked;
254 ItemCheckedEventArgs args = new ItemCheckedEventArgs (this);
255 owner.OnItemChecked (args);
264 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
265 public bool Focused {
266 get { return is_focused; }
268 if (is_focused == value)
281 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
286 else if (owner != null)
289 return ThemeEngine.Current.DefaultFont;
303 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
304 public Color ForeColor {
306 if (sub_items.Count > 0)
307 return sub_items[0].ForeColor;
310 return owner.ForeColor;
312 return ThemeEngine.Current.ColorWindowText;
314 set { SubItems [0].ForeColor = value; }
318 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
319 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
320 typeof (System.Drawing.Design.UITypeEditor))]
323 [RefreshProperties (RefreshProperties.Repaint)]
324 // [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
326 [TypeConverter (typeof (ImageIndexConverter))]
328 public int ImageIndex {
329 get { return image_index; }
332 throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
336 image_key = String.Empty;
347 [LocalizableAttribute (true)]
348 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
349 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
350 typeof (System.Drawing.Design.UITypeEditor))]
351 [RefreshProperties (RefreshProperties.Repaint)]
352 // XXX [TypeConverter (typeof (ImageKeyConverter))
353 public string ImageKey {
358 image_key = value == null ? String.Empty : value;
369 public ImageList ImageList {
373 else if (owner.View == View.LargeIcon)
374 return owner.large_image_list;
376 return owner.small_image_list;
386 if (owner.VirtualMode)
390 return owner.Items.IndexOf (this);
395 public ListView ListView {
396 get { return owner; }
402 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
408 name = value == null ? String.Empty : value;
414 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
415 public bool Selected {
420 if (selected == value)
424 if (value && !owner.MultiSelect)
425 owner.SelectedItems.Clear ();
427 // force re-population of list
428 owner.SelectedIndices.Reset ();
430 owner.OnSelectedIndexChanged ();
439 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
440 typeof (System.Drawing.Design.UITypeEditor))]
443 [RefreshProperties (RefreshProperties.Repaint)]
444 // XXX [RelatedImageListAttribute ("ListView.StateImageList")]
445 // XXX [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
447 [TypeConverter (typeof (ImageIndexConverter))]
449 public int StateImageIndex {
450 get { return state_image_index; }
452 if (value < -1 || value > 14)
453 throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
455 state_image_index = value;
459 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
461 [Editor ("System.Windows.Forms.Design.ListViewSubItemCollectionEditor, " + Consts.AssemblySystem_Design,
462 typeof (System.Drawing.Design.UITypeEditor))]
464 public ListViewSubItemCollection SubItems {
466 if (sub_items.Count == 0)
467 this.sub_items.Add (string.Empty);
473 [DefaultValue (null)]
474 [Localizable (false)]
475 [TypeConverter (typeof (StringConverter))]
482 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
485 if (this.sub_items.Count > 0)
486 return this.sub_items [0].Text;
491 if (SubItems [0].Text == value)
494 sub_items [0].Text = value;
502 [DefaultValue (true)]
503 public bool UseItemStyleForSubItems {
504 get { return use_item_style; }
505 set { use_item_style = value; }
509 [LocalizableAttribute(true)]
510 [DefaultValue (null)]
511 public ListViewGroup Group {
512 get { return this.group; }
515 if (this.group != value)
519 value.Items.Add(this);
521 if (this.group != null)
522 this.group.Items.Remove(this);
528 if(this.group != null)
529 this.group.Items.Remove(this);
536 #endregion // Public Instance Properties
538 #region Public Instance Methods
539 public void BeginEdit ()
541 if (owner != null && owner.LabelEdit) {
542 owner.item_control.BeginEdit (this);
545 // if (owner != null && owner.LabelEdit
546 // && owner.Activation == ItemActivation.Standard)
549 // throw new InvalidOperationException ();
552 public virtual object Clone ()
554 ListViewItem clone = new ListViewItem ();
555 clone.image_index = this.image_index;
556 clone.is_checked = this.is_checked;
557 clone.is_focused = this.is_focused;
558 clone.selected = this.selected;
559 clone.font = this.font;
560 clone.state_image_index = this.state_image_index;
561 clone.sub_items = new ListViewSubItemCollection (this);
563 foreach (ListViewSubItem subItem in this.sub_items)
564 clone.sub_items.Add (subItem.Text, subItem.ForeColor,
565 subItem.BackColor, subItem.Font);
566 clone.tag = this.tag;
567 clone.use_item_style = this.use_item_style;
576 public virtual void EnsureVisible ()
578 if (this.owner != null) {
579 owner.EnsureVisible (owner.Items.IndexOf (this));
583 public Rectangle GetBounds (ItemBoundsPortion portion)
586 return Rectangle.Empty;
591 case ItemBoundsPortion.Icon:
595 case ItemBoundsPortion.Label:
599 case ItemBoundsPortion.ItemOnly:
603 case ItemBoundsPortion.Entire:
608 throw new ArgumentException ("Invalid value for portion.");
611 Point item_loc = owner.GetItemLocation (Index);
612 rect.X += item_loc.X;
613 rect.Y += item_loc.Y;
617 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
622 public virtual void Remove ()
627 owner.item_control.CancelEdit (this);
628 owner.Items.Remove (this);
632 public override string ToString ()
634 return string.Format ("ListViewItem: {0}", this.Text);
636 #endregion // Public Instance Methods
638 #region Protected Methods
639 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
644 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
648 #endregion // Protected Methods
650 #region Private Internal Methods
651 internal Rectangle CheckRectReal {
653 Rectangle rect = checkbox_rect;
654 Point item_loc = owner.GetItemLocation (Index);
655 rect.X += item_loc.X;
656 rect.Y += item_loc.Y;
661 Rectangle text_bounds;
662 internal Rectangle TextBounds {
664 Rectangle result = text_bounds;
665 Point loc = owner.GetItemLocation (Index);
672 internal ListView Owner {
682 internal void SetIndex (int index)
688 internal void Invalidate ()
690 if (owner == null || owner.item_control == null)
693 owner.item_control.Invalidate (Bounds);
696 internal void Layout ()
700 Size text_size = owner.text_size;
702 checkbox_rect = Rectangle.Empty;
703 if (owner.CheckBoxes)
704 checkbox_rect.Size = owner.CheckBoxSize;
705 switch (owner.View) {
707 // LAMESPEC: MSDN says, "In all views except the details
708 // view of the ListView, this value specifies the same
709 // bounding rectangle as the Entire value." Actually, it
710 // returns same bounding rectangles for Item and Entire
711 // values in the case of Details view.
713 // Handle reordered column
714 if (owner.Columns.Count > 0)
715 checkbox_rect.X = owner.Columns[0].Rect.X;
717 icon_rect = label_rect = Rectangle.Empty;
718 icon_rect.X = checkbox_rect.Right + 2;
719 item_ht = owner.ItemSize.Height;
721 if (owner.SmallImageList != null)
722 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
724 label_rect.Height = icon_rect.Height = item_ht;
725 checkbox_rect.Y = item_ht - checkbox_rect.Height;
727 label_rect.X = icon_rect.Right + 1;
729 if (owner.Columns.Count > 0)
730 label_rect.Width = owner.Columns[0].Wd - label_rect.X + checkbox_rect.X;
732 label_rect.Width = text_size.Width;
734 SizeF text_sz = owner.DeviceContext.MeasureString (Text, Font);
735 text_bounds = label_rect;
736 text_bounds.Width = (int) text_sz.Width;
738 item_rect = total = Rectangle.Union
739 (Rectangle.Union (checkbox_rect, icon_rect), label_rect);
740 bounds.Size = total.Size;
744 for (int i = 0; i < owner.Columns.Count; i++) {
745 item_rect.Width += owner.Columns [i].Wd;
746 bounds.Width += owner.Columns [i].Wd;
751 label_rect = icon_rect = Rectangle.Empty;
753 SizeF sz = owner.DeviceContext.MeasureString (Text, Font);
754 if ((int) sz.Width > text_size.Width) {
755 if (Focused && owner.InternalContainsFocus) {
756 int text_width = text_size.Width;
757 StringFormat format = new StringFormat ();
758 format.Alignment = StringAlignment.Center;
759 sz = owner.DeviceContext.MeasureString (Text, Font, text_width, format);
760 text_size.Height = (int) sz.Height;
762 text_size.Height = 2 * (int) sz.Height;
765 if (owner.LargeImageList != null) {
766 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
767 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
770 if (checkbox_rect.Height > icon_rect.Height)
771 icon_rect.Y = checkbox_rect.Height - icon_rect.Height;
773 checkbox_rect.Y = icon_rect.Height - checkbox_rect.Height;
775 if (text_size.Width <= icon_rect.Width) {
776 icon_rect.X = checkbox_rect.Width + 1;
777 label_rect.X = icon_rect.X + (icon_rect.Width - text_size.Width) / 2;
778 label_rect.Y = icon_rect.Bottom + 2;
779 label_rect.Size = text_size;
781 int centerX = text_size.Width / 2;
782 icon_rect.X = checkbox_rect.Width + 1 + centerX - icon_rect.Width / 2;
783 label_rect.X = checkbox_rect.Width + 1;
784 label_rect.Y = icon_rect.Bottom + 2;
785 label_rect.Size = text_size;
788 item_rect = Rectangle.Union (icon_rect, label_rect);
789 total = Rectangle.Union (item_rect, checkbox_rect);
790 bounds.Size = total.Size;
795 label_rect = icon_rect = Rectangle.Empty;
796 icon_rect.X = checkbox_rect.Width + 1;
797 item_ht = Math.Max (owner.CheckBoxSize.Height, text_size.Height);
799 if (owner.SmallImageList != null) {
800 item_ht = Math.Max (item_ht, owner.SmallImageList.ImageSize.Height);
801 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
802 icon_rect.Height = owner.SmallImageList.ImageSize.Height;
805 checkbox_rect.Y = item_ht - checkbox_rect.Height;
806 label_rect.X = icon_rect.Right + 1;
807 label_rect.Width = text_size.Width;
808 label_rect.Height = icon_rect.Height = item_ht;
810 item_rect = Rectangle.Union (icon_rect, label_rect);
811 total = Rectangle.Union (item_rect, checkbox_rect);
812 bounds.Size = total.Size;
816 label_rect = icon_rect = Rectangle.Empty;
818 if (owner.LargeImageList != null) {
819 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
820 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
824 SizeF tsize = owner.DeviceContext.MeasureString (Text, Font);
826 // Set initial values for subitem's layout
827 int total_height = (int)Math.Ceiling (tsize.Height);
828 int max_subitem_width = (int)Math.Ceiling (tsize.Width);
829 SubItems [0].bounds.Height = total_height;
831 int count = Math.Min (owner.Columns.Count, SubItems.Count);
832 for (int i = 1; i < count; i++) { // Ignore first column and first subitem
833 ListViewSubItem sub_item = SubItems [i];
834 if (sub_item.Text == null || sub_item.Text.Length == 0)
837 tsize = owner.DeviceContext.MeasureString (sub_item.Text, sub_item.Font);
839 int width = (int)Math.Ceiling (tsize.Width);
841 if (width > max_subitem_width)
842 max_subitem_width = width;
844 int height = (int)Math.Ceiling (tsize.Height);
845 total_height += height + separation;
847 sub_item.bounds.Height = height;
851 label_rect.X = icon_rect.Right + 4;
852 label_rect.Y = owner.TileSize.Height / 2 - total_height / 2;
853 label_rect.Width = max_subitem_width;
854 label_rect.Height = total_height;
856 // Second pass for assigning bounds. This time take first subitem into account.
857 int current_y = label_rect.Y;
858 for (int j = 0; j < count; j++) {
859 ListViewSubItem sub_item = SubItems [j];
860 if (sub_item.Text == null || sub_item.Text.Length == 0)
863 sub_item.SetBounds (label_rect.X, current_y, max_subitem_width, sub_item.bounds.Height);
864 current_y += sub_item.Bounds.Height + separation;
867 item_rect = Rectangle.Union (icon_rect, label_rect);
868 bounds.Size = item_rect.Size;
874 #endregion // Private Internal Methods
878 [DefaultProperty ("Text")]
879 [DesignTimeVisible (false)]
881 [ToolboxItem (false)]
882 [TypeConverter (typeof(ListViewSubItemConverter))]
883 public class ListViewSubItem
885 private Color back_color;
887 private Color fore_color;
888 internal ListViewItem owner;
889 private string text = string.Empty;
891 private string name = String.Empty;
893 internal Rectangle bounds;
896 #region Public Constructors
897 public ListViewSubItem ()
901 public ListViewSubItem (ListViewItem owner, string text)
902 : this (owner, text, Color.Empty,
907 public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
908 Color backColor, Font font)
912 this.fore_color = foreColor;
913 this.back_color = backColor;
916 #endregion // Public Constructors
918 #region Public Instance Properties
919 public Color BackColor {
921 if (this.back_color != Color.Empty)
922 return this.back_color;
923 if (this.owner != null && this.owner.ListView != null)
924 return this.owner.ListView.BackColor;
925 return ThemeEngine.Current.ColorWindow;
934 public Rectangle Bounds {
936 Rectangle retval = bounds;
938 retval.X += owner.Bounds.X;
939 retval.Y += owner.Bounds.Y;
952 else if (owner != null)
954 return ThemeEngine.Current.DefaultFont;
964 public Color ForeColor {
966 if (this.fore_color != Color.Empty)
967 return this.fore_color;
968 if (this.owner != null && this.owner.ListView != null)
969 return this.owner.ListView.ForeColor;
970 return ThemeEngine.Current.ColorWindowText;
985 name = value == null ? String.Empty : value;
989 [TypeConverter (typeof (StringConverter))]
990 [BindableAttribute (true)]
991 [DefaultValue (null)]
992 [Localizable (false)]
1003 [Localizable (true)]
1004 public string Text {
1005 get { return text; }
1011 text = string.Empty;
1018 #endregion // Public Instance Properties
1020 #region Public Methods
1021 public void ResetStyle ()
1023 font = ThemeEngine.Current.DefaultFont;
1024 back_color = ThemeEngine.Current.DefaultControlBackColor;
1025 fore_color = ThemeEngine.Current.DefaultControlForeColor;
1029 public override string ToString ()
1031 return string.Format ("ListViewSubItem {{0}}", text);
1033 #endregion // Public Methods
1036 #region Private Methods
1037 private void Invalidate ()
1039 if (owner == null || owner.owner == null)
1042 owner.owner.Invalidate ();
1046 internal int Height {
1048 return bounds.Height;
1052 internal void SetBounds (int x, int y, int width, int height)
1054 bounds = new Rectangle (x, y, width, height);
1057 #endregion // Private Methods
1060 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
1062 private ArrayList list;
1063 internal ListViewItem owner;
1065 #region Public Constructors
1066 public ListViewSubItemCollection (ListViewItem owner)
1069 this.list = new ArrayList ();
1071 #endregion // Public Constructors
1073 #region Public Properties
1076 get { return list.Count; }
1079 public bool IsReadOnly {
1080 get { return false; }
1083 public ListViewSubItem this [int index] {
1084 get { return (ListViewSubItem) list [index]; }
1086 value.owner = this.owner;
1087 list [index] = value;
1092 public virtual ListViewSubItem this [string key] {
1094 int idx = IndexOfKey (key);
1098 return (ListViewSubItem) list [idx];
1103 bool ICollection.IsSynchronized {
1104 get { return list.IsSynchronized; }
1107 object ICollection.SyncRoot {
1108 get { return list.SyncRoot; }
1111 bool IList.IsFixedSize {
1112 get { return list.IsFixedSize; }
1115 object IList.this [int index] {
1116 get { return this [index]; }
1118 if (! (value is ListViewSubItem))
1119 throw new ArgumentException ("Not of type ListViewSubItem", "value");
1120 this [index] = (ListViewSubItem) value;
1123 #endregion // Public Properties
1125 #region Public Methods
1126 public ListViewSubItem Add (ListViewSubItem item)
1128 item.owner = this.owner;
1133 public ListViewSubItem Add (string text)
1135 ListViewSubItem item = new ListViewSubItem (this.owner, text);
1140 public ListViewSubItem Add (string text, Color foreColor,
1141 Color backColor, Font font)
1143 ListViewSubItem item = new ListViewSubItem (this.owner, text,
1144 foreColor, backColor, font);
1149 public void AddRange (ListViewSubItem [] items)
1152 throw new ArgumentNullException ("items");
1154 foreach (ListViewSubItem item in items) {
1161 public void AddRange (string [] items)
1164 throw new ArgumentNullException ("items");
1166 foreach (string item in items) {
1173 public void AddRange (string [] items, Color foreColor,
1174 Color backColor, Font font)
1177 throw new ArgumentNullException ("items");
1179 foreach (string item in items) {
1182 this.Add (item, foreColor, backColor, font);
1186 public void Clear ()
1191 public bool Contains (ListViewSubItem item)
1193 return list.Contains (item);
1197 public virtual bool ContainsKey (string key)
1199 return IndexOfKey (key) != -1;
1203 public IEnumerator GetEnumerator ()
1205 return list.GetEnumerator ();
1208 void ICollection.CopyTo (Array dest, int index)
1210 list.CopyTo (dest, index);
1213 int IList.Add (object item)
1215 if (! (item is ListViewSubItem)) {
1216 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1219 ListViewSubItem sub_item = (ListViewSubItem) item;
1220 sub_item.owner = this.owner;
1221 return list.Add (sub_item);
1224 bool IList.Contains (object subItem)
1226 if (! (subItem is ListViewSubItem)) {
1227 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1230 return this.Contains ((ListViewSubItem) subItem);
1233 int IList.IndexOf (object subItem)
1235 if (! (subItem is ListViewSubItem)) {
1236 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1239 return this.IndexOf ((ListViewSubItem) subItem);
1242 void IList.Insert (int index, object item)
1244 if (! (item is ListViewSubItem)) {
1245 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1248 this.Insert (index, (ListViewSubItem) item);
1251 void IList.Remove (object item)
1253 if (! (item is ListViewSubItem)) {
1254 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1257 this.Remove ((ListViewSubItem) item);
1260 public int IndexOf (ListViewSubItem subItem)
1262 return list.IndexOf (subItem);
1266 public virtual int IndexOfKey (string key)
1268 if (key == null || key.Length == 0)
1271 for (int i = 0; i < list.Count; i++) {
1272 ListViewSubItem l = (ListViewSubItem) list [i];
1273 if (String.Compare (l.Name, key, true) == 0)
1281 public void Insert (int index, ListViewSubItem item)
1283 item.owner = this.owner;
1284 list.Insert (index, item);
1287 public void Remove (ListViewSubItem item)
1293 public virtual void RemoveByKey (string key)
1295 int idx = IndexOfKey (key);
1301 public void RemoveAt (int index)
1303 list.RemoveAt (index);
1305 #endregion // Public Methods
1307 #endregion // Subclasses