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 string tooltip_text = String.Empty;
54 int index; // cached index for VirtualMode
57 Rectangle checkbox_rect; // calculated by CalcListViewItem method
68 #endregion Instance Variables
70 #region Public Constructors
71 public ListViewItem () : this (string.Empty)
75 public ListViewItem (string text) : this (text, -1)
79 public ListViewItem (string [] items) : this (items, -1)
83 public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
85 this.sub_items = new ListViewSubItemCollection (this);
86 for (int i = 0; i < subItems.Length; i++)
87 sub_items.Add (subItems [i]);
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);
102 for (int i = 0; i < items.Length; i++)
103 sub_items.Add (new ListViewSubItem (this, items [i]));
105 this.image_index = imageIndex;
108 public ListViewItem (string [] items, int imageIndex, Color foreColor,
109 Color backColor, Font font) : this (items, imageIndex)
111 ForeColor = foreColor;
112 BackColor = backColor;
117 public ListViewItem(string[] items, string imageKey) : this(items)
119 this.ImageKey = imageKey;
122 public ListViewItem(string text, string imageKey) : this(text)
124 this.ImageKey = imageKey;
127 public ListViewItem(ListViewSubItem[] subItems, string imageKey)
129 this.sub_items = new ListViewSubItemCollection (this);
130 for (int i = 0; i < subItems.Length; i++)
131 this.sub_items.Add (subItems [i]);
132 this.ImageKey = imageKey;
135 public ListViewItem(string[] items, string imageKey, Color foreColor,
136 Color backColor, Font font) : this(items, imageKey)
138 ForeColor = foreColor;
139 BackColor = backColor;
143 public ListViewItem(ListViewGroup group) : this()
148 public ListViewItem(string text, ListViewGroup group) : this(text)
153 public ListViewItem(string[] items, ListViewGroup group) : this(items)
158 public ListViewItem(ListViewSubItem[] subItems, int imageIndex, ListViewGroup group)
159 : this(subItems, imageIndex)
164 public ListViewItem(ListViewSubItem[] subItems, string imageKey, ListViewGroup group)
165 : this(subItems, imageKey)
170 public ListViewItem(string text, int imageIndex, ListViewGroup group)
171 : this(text, imageIndex)
176 public ListViewItem(string text, string imageKey, ListViewGroup group)
177 : this(text, imageKey)
182 public ListViewItem(string[] items, int imageIndex, ListViewGroup group)
183 : this(items, imageIndex)
188 public ListViewItem(string[] items, string imageKey, ListViewGroup group)
189 : this(items, imageKey)
194 public ListViewItem(string[] items, int imageIndex, Color foreColor, Color backColor,
195 Font font, ListViewGroup group)
196 : this(items, imageIndex, foreColor, backColor, font)
201 public ListViewItem(string[] items, string imageKey, Color foreColor, Color backColor,
202 Font font, ListViewGroup group)
203 : this(items, imageKey, foreColor, backColor, font)
208 #endregion // Public Constructors
210 #region Public Instance Properties
211 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
212 public Color BackColor {
214 if (sub_items.Count > 0)
215 return sub_items[0].BackColor;
218 return owner.BackColor;
220 return ThemeEngine.Current.ColorWindow;
222 set { SubItems [0].BackColor = value; }
226 public Rectangle Bounds {
228 return GetBounds (ItemBoundsPortion.Entire);
232 [DefaultValue (false)]
233 [RefreshProperties (RefreshProperties.Repaint)]
234 public bool Checked {
235 get { return is_checked; }
237 if (is_checked == value)
241 CheckState current_value = is_checked ? CheckState.Checked : CheckState.Unchecked;
242 CheckState new_value = value ? CheckState.Checked : CheckState.Unchecked;
244 ItemCheckEventArgs icea = new ItemCheckEventArgs (Index,
245 new_value, current_value);
246 owner.OnItemCheck (icea);
248 if (new_value != current_value) {
249 // force re-population of list
250 owner.CheckedItems.Reset ();
251 is_checked = new_value == CheckState.Checked;
255 ItemCheckedEventArgs args = new ItemCheckedEventArgs (this);
256 owner.OnItemChecked (args);
265 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
266 public bool Focused {
267 get { return is_focused; }
269 if (is_focused == value)
282 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
287 else if (owner != null)
290 return ThemeEngine.Current.DefaultFont;
304 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
305 public Color ForeColor {
307 if (sub_items.Count > 0)
308 return sub_items[0].ForeColor;
311 return owner.ForeColor;
313 return ThemeEngine.Current.ColorWindowText;
315 set { SubItems [0].ForeColor = value; }
319 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
320 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
321 typeof (System.Drawing.Design.UITypeEditor))]
324 [RefreshProperties (RefreshProperties.Repaint)]
325 // [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
327 [TypeConverter (typeof (ImageIndexConverter))]
329 public int ImageIndex {
330 get { return image_index; }
333 throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
337 image_key = String.Empty;
348 [LocalizableAttribute (true)]
349 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
350 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
351 typeof (System.Drawing.Design.UITypeEditor))]
352 [RefreshProperties (RefreshProperties.Repaint)]
353 // XXX [TypeConverter (typeof (ImageKeyConverter))
354 public string ImageKey {
359 image_key = value == null ? String.Empty : value;
370 public ImageList ImageList {
374 else if (owner.View == View.LargeIcon)
375 return owner.large_image_list;
377 return owner.small_image_list;
387 if (owner.VirtualMode)
391 return owner.Items.IndexOf (this);
396 public ListView ListView {
397 get { return owner; }
403 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
409 name = value == null ? String.Empty : value;
414 // When ListView uses VirtualMode, selection state info
415 // lives in the ListView, not in the item
417 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
418 public bool Selected {
421 if (owner != null && owner.VirtualMode)
422 return owner.SelectedIndices.Contains (Index);
429 if (selected == value && owner != null && !owner.VirtualMode)
431 if (selected == value)
436 if (value && !owner.MultiSelect)
437 owner.SelectedIndices.Clear ();
439 if (owner.VirtualMode)
441 owner.SelectedIndices.InsertIndex (Index);
443 owner.SelectedIndices.RemoveIndex (Index);
448 // force re-population of list
449 owner.SelectedIndices.Reset ();
451 owner.OnItemSelectionChanged (new ListViewItemSelectionChangedEventArgs (this, Index, value));
453 owner.OnSelectedIndexChanged ();
462 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
463 typeof (System.Drawing.Design.UITypeEditor))]
466 [RefreshProperties (RefreshProperties.Repaint)]
467 // XXX [RelatedImageListAttribute ("ListView.StateImageList")]
468 // XXX [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
470 [TypeConverter (typeof (ImageIndexConverter))]
472 public int StateImageIndex {
473 get { return state_image_index; }
475 if (value < -1 || value > 14)
476 throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
478 state_image_index = value;
482 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
484 [Editor ("System.Windows.Forms.Design.ListViewSubItemCollectionEditor, " + Consts.AssemblySystem_Design,
485 typeof (System.Drawing.Design.UITypeEditor))]
487 public ListViewSubItemCollection SubItems {
489 if (sub_items.Count == 0)
490 this.sub_items.Add (string.Empty);
496 [DefaultValue (null)]
497 [Localizable (false)]
498 [TypeConverter (typeof (StringConverter))]
505 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
508 if (this.sub_items.Count > 0)
509 return this.sub_items [0].Text;
514 if (SubItems [0].Text == value)
517 sub_items [0].Text = value;
525 [DefaultValue (true)]
526 public bool UseItemStyleForSubItems {
527 get { return use_item_style; }
528 set { use_item_style = value; }
532 [LocalizableAttribute(true)]
533 [DefaultValue (null)]
534 public ListViewGroup Group {
535 get { return this.group; }
538 if (this.group != value)
542 value.Items.Add(this);
544 if (this.group != null)
545 this.group.Items.Remove(this);
551 if(this.group != null)
552 this.group.Items.Remove(this);
559 public string ToolTipText {
565 value = String.Empty;
567 tooltip_text = value;
572 #endregion // Public Instance Properties
574 #region Public Instance Methods
575 public void BeginEdit ()
577 if (owner != null && owner.LabelEdit) {
578 owner.item_control.BeginEdit (this);
581 // if (owner != null && owner.LabelEdit
582 // && owner.Activation == ItemActivation.Standard)
585 // throw new InvalidOperationException ();
588 public virtual object Clone ()
590 ListViewItem clone = new ListViewItem ();
591 clone.image_index = this.image_index;
592 clone.is_checked = this.is_checked;
593 clone.is_focused = this.is_focused;
594 clone.selected = this.selected;
595 clone.font = this.font;
596 clone.state_image_index = this.state_image_index;
597 clone.sub_items = new ListViewSubItemCollection (this);
599 foreach (ListViewSubItem subItem in this.sub_items)
600 clone.sub_items.Add (subItem.Text, subItem.ForeColor,
601 subItem.BackColor, subItem.Font);
602 clone.tag = this.tag;
603 clone.use_item_style = this.use_item_style;
607 clone.tooltip_text = tooltip_text;
613 public virtual void EnsureVisible ()
615 if (this.owner != null) {
616 owner.EnsureVisible (owner.Items.IndexOf (this));
620 public Rectangle GetBounds (ItemBoundsPortion portion)
623 return Rectangle.Empty;
628 // Can't cache bounds in Virtual mode,
629 // since we can get different item instances at each invocation
630 if (owner.VirtualMode)
634 case ItemBoundsPortion.Icon:
638 case ItemBoundsPortion.Label:
642 case ItemBoundsPortion.ItemOnly:
646 case ItemBoundsPortion.Entire:
651 throw new ArgumentException ("Invalid value for portion.");
654 Point item_loc = owner.GetItemLocation (Index);
655 rect.X += item_loc.X;
656 rect.Y += item_loc.Y;
660 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
665 public virtual void Remove ()
670 owner.item_control.CancelEdit (this);
671 owner.Items.Remove (this);
675 public override string ToString ()
677 return string.Format ("ListViewItem: {0}", this.Text);
679 #endregion // Public Instance Methods
681 #region Protected Methods
682 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
687 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
691 #endregion // Protected Methods
693 #region Private Internal Methods
694 internal Rectangle CheckRectReal {
696 Rectangle rect = checkbox_rect;
697 Point item_loc = owner.GetItemLocation (Index);
698 rect.X += item_loc.X;
699 rect.Y += item_loc.Y;
704 Rectangle text_bounds;
705 internal Rectangle TextBounds {
707 Rectangle result = text_bounds;
708 Point loc = owner.GetItemLocation (Index);
715 internal ListView Owner {
725 internal void SetIndex (int index)
731 internal void Invalidate ()
733 if (owner == null || owner.item_control == null)
736 owner.item_control.Invalidate (Bounds);
739 internal void Layout ()
745 Size text_size = owner.text_size;
747 checkbox_rect = Rectangle.Empty;
748 if (owner.CheckBoxes)
749 checkbox_rect.Size = owner.CheckBoxSize;
750 switch (owner.View) {
752 // LAMESPEC: MSDN says, "In all views except the details
753 // view of the ListView, this value specifies the same
754 // bounding rectangle as the Entire value." Actually, it
755 // returns same bounding rectangles for Item and Entire
756 // values in the case of Details view.
758 // Handle reordered column
759 if (owner.Columns.Count > 0)
760 checkbox_rect.X = owner.Columns[0].Rect.X;
762 icon_rect = label_rect = Rectangle.Empty;
763 icon_rect.X = checkbox_rect.Right + 2;
764 item_ht = owner.ItemSize.Height;
766 if (owner.SmallImageList != null)
767 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
769 label_rect.Height = icon_rect.Height = item_ht;
770 checkbox_rect.Y = item_ht - checkbox_rect.Height;
772 label_rect.X = icon_rect.Right + 1;
774 if (owner.Columns.Count > 0)
775 label_rect.Width = owner.Columns[0].Wd - label_rect.X + checkbox_rect.X;
777 label_rect.Width = text_size.Width;
779 SizeF text_sz = owner.DeviceContext.MeasureString (Text, Font);
780 text_bounds = label_rect;
781 text_bounds.Width = (int) text_sz.Width;
783 item_rect = total = Rectangle.Union
784 (Rectangle.Union (checkbox_rect, icon_rect), label_rect);
785 bounds.Size = total.Size;
789 for (int i = 0; i < owner.Columns.Count; i++) {
790 item_rect.Width += owner.Columns [i].Wd;
791 bounds.Width += owner.Columns [i].Wd;
796 label_rect = icon_rect = Rectangle.Empty;
798 SizeF sz = owner.DeviceContext.MeasureString (Text, Font);
799 if ((int) sz.Width > text_size.Width) {
800 if (Focused && owner.InternalContainsFocus) {
801 int text_width = text_size.Width;
802 StringFormat format = new StringFormat ();
803 format.Alignment = StringAlignment.Center;
804 sz = owner.DeviceContext.MeasureString (Text, Font, text_width, format);
805 text_size.Height = (int) sz.Height;
807 text_size.Height = 2 * (int) sz.Height;
810 if (owner.LargeImageList != null) {
811 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
812 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
815 if (checkbox_rect.Height > icon_rect.Height)
816 icon_rect.Y = checkbox_rect.Height - icon_rect.Height;
818 checkbox_rect.Y = icon_rect.Height - checkbox_rect.Height;
820 if (text_size.Width <= icon_rect.Width) {
821 icon_rect.X = checkbox_rect.Width + 1;
822 label_rect.X = icon_rect.X + (icon_rect.Width - text_size.Width) / 2;
823 label_rect.Y = icon_rect.Bottom + 2;
824 label_rect.Size = text_size;
826 int centerX = text_size.Width / 2;
827 icon_rect.X = checkbox_rect.Width + 1 + centerX - icon_rect.Width / 2;
828 label_rect.X = checkbox_rect.Width + 1;
829 label_rect.Y = icon_rect.Bottom + 2;
830 label_rect.Size = text_size;
833 item_rect = Rectangle.Union (icon_rect, label_rect);
834 total = Rectangle.Union (item_rect, checkbox_rect);
835 bounds.Size = total.Size;
840 label_rect = icon_rect = Rectangle.Empty;
841 icon_rect.X = checkbox_rect.Width + 1;
842 item_ht = Math.Max (owner.CheckBoxSize.Height, text_size.Height);
844 if (owner.SmallImageList != null) {
845 item_ht = Math.Max (item_ht, owner.SmallImageList.ImageSize.Height);
846 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
847 icon_rect.Height = owner.SmallImageList.ImageSize.Height;
850 checkbox_rect.Y = item_ht - checkbox_rect.Height;
851 label_rect.X = icon_rect.Right + 1;
852 label_rect.Width = text_size.Width;
853 label_rect.Height = icon_rect.Height = item_ht;
855 item_rect = Rectangle.Union (icon_rect, label_rect);
856 total = Rectangle.Union (item_rect, checkbox_rect);
857 bounds.Size = total.Size;
861 label_rect = icon_rect = Rectangle.Empty;
863 if (owner.LargeImageList != null) {
864 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
865 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
869 SizeF tsize = owner.DeviceContext.MeasureString (Text, Font);
871 // Set initial values for subitem's layout
872 int total_height = (int)Math.Ceiling (tsize.Height);
873 int max_subitem_width = (int)Math.Ceiling (tsize.Width);
874 SubItems [0].bounds.Height = total_height;
876 int count = Math.Min (owner.Columns.Count, SubItems.Count);
877 for (int i = 1; i < count; i++) { // Ignore first column and first subitem
878 ListViewSubItem sub_item = SubItems [i];
879 if (sub_item.Text == null || sub_item.Text.Length == 0)
882 tsize = owner.DeviceContext.MeasureString (sub_item.Text, sub_item.Font);
884 int width = (int)Math.Ceiling (tsize.Width);
886 if (width > max_subitem_width)
887 max_subitem_width = width;
889 int height = (int)Math.Ceiling (tsize.Height);
890 total_height += height + separation;
892 sub_item.bounds.Height = height;
896 label_rect.X = icon_rect.Right + 4;
897 label_rect.Y = owner.TileSize.Height / 2 - total_height / 2;
898 label_rect.Width = max_subitem_width;
899 label_rect.Height = total_height;
901 // Second pass for assigning bounds. This time take first subitem into account.
902 int current_y = label_rect.Y;
903 for (int j = 0; j < count; j++) {
904 ListViewSubItem sub_item = SubItems [j];
905 if (sub_item.Text == null || sub_item.Text.Length == 0)
908 sub_item.SetBounds (label_rect.X, current_y, max_subitem_width, sub_item.bounds.Height);
909 current_y += sub_item.Bounds.Height + separation;
912 item_rect = Rectangle.Union (icon_rect, label_rect);
913 bounds.Size = item_rect.Size;
919 #endregion // Private Internal Methods
923 [DefaultProperty ("Text")]
924 [DesignTimeVisible (false)]
926 [ToolboxItem (false)]
927 [TypeConverter (typeof(ListViewSubItemConverter))]
928 public class ListViewSubItem
930 private Color back_color;
932 private Color fore_color;
933 internal ListViewItem owner;
934 private string text = string.Empty;
936 private string name = String.Empty;
938 internal Rectangle bounds;
941 #region Public Constructors
942 public ListViewSubItem ()
946 public ListViewSubItem (ListViewItem owner, string text)
947 : this (owner, text, Color.Empty,
952 public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
953 Color backColor, Font font)
957 this.fore_color = foreColor;
958 this.back_color = backColor;
961 #endregion // Public Constructors
963 #region Public Instance Properties
964 public Color BackColor {
966 if (this.back_color != Color.Empty)
967 return this.back_color;
968 if (this.owner != null && this.owner.ListView != null)
969 return this.owner.ListView.BackColor;
970 return ThemeEngine.Current.ColorWindow;
979 public Rectangle Bounds {
981 Rectangle retval = bounds;
983 retval.X += owner.Bounds.X;
984 retval.Y += owner.Bounds.Y;
997 else if (owner != null)
999 return ThemeEngine.Current.DefaultFont;
1009 public Color ForeColor {
1011 if (this.fore_color != Color.Empty)
1012 return this.fore_color;
1013 if (this.owner != null && this.owner.ListView != null)
1014 return this.owner.ListView.ForeColor;
1015 return ThemeEngine.Current.ColorWindowText;
1024 [Localizable (true)]
1025 public string Name {
1030 name = value == null ? String.Empty : value;
1034 [TypeConverter (typeof (StringConverter))]
1035 [BindableAttribute (true)]
1036 [DefaultValue (null)]
1037 [Localizable (false)]
1048 [Localizable (true)]
1049 public string Text {
1050 get { return text; }
1056 text = string.Empty;
1063 #endregion // Public Instance Properties
1065 #region Public Methods
1066 public void ResetStyle ()
1068 font = ThemeEngine.Current.DefaultFont;
1069 back_color = ThemeEngine.Current.DefaultControlBackColor;
1070 fore_color = ThemeEngine.Current.DefaultControlForeColor;
1074 public override string ToString ()
1076 return string.Format ("ListViewSubItem {{0}}", text);
1078 #endregion // Public Methods
1081 #region Private Methods
1082 private void Invalidate ()
1084 if (owner == null || owner.owner == null)
1087 owner.owner.Invalidate ();
1091 internal int Height {
1093 return bounds.Height;
1097 internal void SetBounds (int x, int y, int width, int height)
1099 bounds = new Rectangle (x, y, width, height);
1102 #endregion // Private Methods
1105 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
1107 private ArrayList list;
1108 internal ListViewItem owner;
1110 #region Public Constructors
1111 public ListViewSubItemCollection (ListViewItem owner)
1114 this.list = new ArrayList ();
1116 #endregion // Public Constructors
1118 #region Public Properties
1121 get { return list.Count; }
1124 public bool IsReadOnly {
1125 get { return false; }
1128 public ListViewSubItem this [int index] {
1129 get { return (ListViewSubItem) list [index]; }
1131 value.owner = this.owner;
1132 list [index] = value;
1137 public virtual ListViewSubItem this [string key] {
1139 int idx = IndexOfKey (key);
1143 return (ListViewSubItem) list [idx];
1148 bool ICollection.IsSynchronized {
1149 get { return list.IsSynchronized; }
1152 object ICollection.SyncRoot {
1153 get { return list.SyncRoot; }
1156 bool IList.IsFixedSize {
1157 get { return list.IsFixedSize; }
1160 object IList.this [int index] {
1161 get { return this [index]; }
1163 if (! (value is ListViewSubItem))
1164 throw new ArgumentException ("Not of type ListViewSubItem", "value");
1165 this [index] = (ListViewSubItem) value;
1168 #endregion // Public Properties
1170 #region Public Methods
1171 public ListViewSubItem Add (ListViewSubItem item)
1173 item.owner = this.owner;
1178 public ListViewSubItem Add (string text)
1180 ListViewSubItem item = new ListViewSubItem (this.owner, text);
1185 public ListViewSubItem Add (string text, Color foreColor,
1186 Color backColor, Font font)
1188 ListViewSubItem item = new ListViewSubItem (this.owner, text,
1189 foreColor, backColor, font);
1194 public void AddRange (ListViewSubItem [] items)
1197 throw new ArgumentNullException ("items");
1199 foreach (ListViewSubItem item in items) {
1206 public void AddRange (string [] items)
1209 throw new ArgumentNullException ("items");
1211 foreach (string item in items) {
1218 public void AddRange (string [] items, Color foreColor,
1219 Color backColor, Font font)
1222 throw new ArgumentNullException ("items");
1224 foreach (string item in items) {
1227 this.Add (item, foreColor, backColor, font);
1231 public void Clear ()
1236 public bool Contains (ListViewSubItem item)
1238 return list.Contains (item);
1242 public virtual bool ContainsKey (string key)
1244 return IndexOfKey (key) != -1;
1248 public IEnumerator GetEnumerator ()
1250 return list.GetEnumerator ();
1253 void ICollection.CopyTo (Array dest, int index)
1255 list.CopyTo (dest, index);
1258 int IList.Add (object item)
1260 if (! (item is ListViewSubItem)) {
1261 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1264 ListViewSubItem sub_item = (ListViewSubItem) item;
1265 sub_item.owner = this.owner;
1266 return list.Add (sub_item);
1269 bool IList.Contains (object subItem)
1271 if (! (subItem is ListViewSubItem)) {
1272 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1275 return this.Contains ((ListViewSubItem) subItem);
1278 int IList.IndexOf (object subItem)
1280 if (! (subItem is ListViewSubItem)) {
1281 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1284 return this.IndexOf ((ListViewSubItem) subItem);
1287 void IList.Insert (int index, object item)
1289 if (! (item is ListViewSubItem)) {
1290 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1293 this.Insert (index, (ListViewSubItem) item);
1296 void IList.Remove (object item)
1298 if (! (item is ListViewSubItem)) {
1299 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1302 this.Remove ((ListViewSubItem) item);
1305 public int IndexOf (ListViewSubItem subItem)
1307 return list.IndexOf (subItem);
1311 public virtual int IndexOfKey (string key)
1313 if (key == null || key.Length == 0)
1316 for (int i = 0; i < list.Count; i++) {
1317 ListViewSubItem l = (ListViewSubItem) list [i];
1318 if (String.Compare (l.Name, key, true) == 0)
1326 public void Insert (int index, ListViewSubItem item)
1328 item.owner = this.owner;
1329 list.Insert (index, item);
1332 public void Remove (ListViewSubItem item)
1338 public virtual void RemoveByKey (string key)
1340 int idx = IndexOfKey (key);
1346 public void RemoveAt (int index)
1348 list.RemoveAt (index);
1350 #endregion // Public Methods
1352 #endregion // Subclasses