* ImageList.cs: When the image stream is set pull all the images
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ListViewItem.cs
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 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Ravindra (rkumar@novell.com)
24 //
25 // Todo:
26 //     - Drawing of focus rectangle
27
28
29
30 // NOT COMPLETE
31
32
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Drawing;
36 using System.Runtime.Serialization;
37
38 namespace System.Windows.Forms
39 {
40         [DefaultProperty ("Text")]
41         [DesignTimeVisible (false)]
42         [Serializable]
43         [ToolboxItem (false)]
44         [TypeConverter (typeof (ListViewItemConverter))]
45         public class ListViewItem : ICloneable, ISerializable
46         {
47                 #region Instance Variables
48                 private Color back_color = Color.Empty;
49                 private Font font = null;
50                 private Color fore_color = Color.Empty;
51                 private int image_index = -1;
52                 private bool is_checked = false;
53                 private bool is_focused = false;
54                 private int state_image_index = -1;
55                 private ListViewSubItemCollection sub_items;
56                 private object tag;
57                 private bool use_item_style = true;
58
59                 // internal variables
60                 internal Rectangle checkbox_rect;       // calculated by CalcListViewItem method
61                 internal Rectangle entire_rect;
62                 internal Rectangle icon_rect;
63                 internal Rectangle item_rect;
64                 internal Rectangle label_rect;
65                 internal Point location = Point.Empty;  // set by the ListView control
66                 internal ListView owner;
67                 internal bool selected;
68
69                 #endregion Instance Variables
70
71                 #region Public Constructors
72                 public ListViewItem ()
73                 {
74                         this.sub_items = new ListViewSubItemCollection (this);
75                         this.sub_items.Add ("");
76                 }
77
78                 public ListViewItem (string text) : this (text, -1)
79                 {
80                 }
81
82                 public ListViewItem (string [] items) : this (items, -1)
83                 {
84                 }
85
86                 public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
87                 {
88                         this.sub_items = new ListViewSubItemCollection (this);
89                         this.sub_items.AddRange (subItems);
90                         this.image_index = imageIndex;
91                 }
92
93                 public ListViewItem (string text, int imageIndex)
94                 {
95                         this.image_index = imageIndex;
96                         this.sub_items = new ListViewSubItemCollection (this);
97                         this.sub_items.Add (text);
98                 }
99
100                 public ListViewItem (string [] items, int imageIndex)
101                 {
102                         this.sub_items = new ListViewSubItemCollection (this);
103                         this.sub_items.AddRange (items);
104                         this.image_index = imageIndex;
105                 }
106
107                 public ListViewItem (string [] items, int imageIndex, Color foreColor, 
108                                      Color backColor, Font font)
109                 {
110                         this.sub_items = new ListViewSubItemCollection (this);
111                         this.sub_items.AddRange (items);
112                         this.image_index = imageIndex;
113                         this.fore_color = foreColor;
114                         this.back_color = backColor;
115                         this.font = font;
116                 }
117                 #endregion      // Public Constructors
118
119                 #region Public Instance Properties
120                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
121                 public Color BackColor {
122                         get {
123                                 if (! back_color.IsEmpty)
124                                         return back_color;
125                                 else if (owner != null)
126                                         return owner.BackColor;
127                                 else
128                                         return ThemeEngine.Current.ColorWindow;
129                         }
130                         set { this.back_color = value; }
131                 }
132
133                 [Browsable (false)]
134                 public Rectangle Bounds {
135                         get {
136                                 return GetBounds (ItemBoundsPortion.Entire);
137                         }
138                 }
139
140                 [DefaultValue (false)]
141                 [RefreshProperties (RefreshProperties.Repaint)]
142                 public bool Checked {
143                         get { return is_checked; }
144                         set { is_checked = value; }
145                 }
146
147                 [Browsable (false)]
148                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
149                 public bool Focused {
150                         get { return is_focused; }
151                         set { is_focused = value; }
152                 }
153
154                 [Localizable (true)]
155                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
156                 public Font Font {
157                         get {
158                                 if (font != null)
159                                         return font;
160                                 else if (owner != null)
161                                         return owner.Font;
162                                 else
163                                         return ThemeEngine.Current.DefaultFont;
164                         }
165                         set { font = value; }
166                 }
167
168                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
169                 public Color ForeColor {
170                         get {
171                                 if (! fore_color.IsEmpty)
172                                         return fore_color;
173                                 else if (owner != null)
174                                         return owner.ForeColor;
175                                 else
176                                         return ThemeEngine.Current.ColorWindowText;
177                         }
178                         set { fore_color = value; }
179                 }
180
181                 [DefaultValue (-1)]
182                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
183                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
184                          typeof (System.Drawing.Design.UITypeEditor))]
185                 [Localizable (true)]
186                 [TypeConverter (typeof (ImageIndexConverter))]
187                 public int ImageIndex {
188                         get { return image_index; }
189                         set {
190                                 if (value < -1)
191                                         throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
192                                 image_index = value;
193                         }
194                 }
195
196                 [Browsable (false)]
197                 public ImageList ImageList {
198                         get {
199                                 if (owner == null)
200                                         return null;
201                                 else if (owner.View == View.LargeIcon)
202                                         return owner.large_image_list;
203                                 else
204                                         return owner.small_image_list;
205                         }
206                 }
207
208                 [Browsable (false)]
209                 public int Index {
210                         get {
211                                 if (owner == null)
212                                         return -1;
213                                 else
214                                         return owner.Items.IndexOf (this);
215                         }
216                 }
217
218                 [Browsable (false)]
219                 public ListView ListView {
220                         get { return owner; }
221                 }
222
223                 [Browsable (false)]
224                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
225                 public bool Selected {
226                         get { return selected; }
227                         set {
228                                 if (owner != null) {
229                                         if (owner.CanMultiselect == false &&
230                                             owner.SelectedItems.Count > 0) {
231                                                 owner.SelectedItems.Clear ();
232                                                 owner.SelectedIndices.list.Clear ();
233                                         }
234
235                                         selected = value;
236                                         if (selected) {
237                                                 //do we need !owner.SelectedItems.Contains (this))
238                                                 owner.SelectedItems.list.Add (this);
239                                                 owner.SelectedIndices.list.Add (this.Index);
240                                         }
241                                         else {
242                                                 owner.SelectedItems.list.Remove (this);
243                                                 owner.SelectedIndices.list.Remove (this.Index);
244                                         }
245                                 }
246                         }
247                 }
248
249                 [DefaultValue (-1)]
250                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
251                          typeof (System.Drawing.Design.UITypeEditor))]
252                 [Localizable (true)]
253                 [TypeConverter (typeof (ImageIndexConverter))]
254                 public int StateImageIndex {
255                         get { return state_image_index; }
256                         set {
257                                 if (value < -1 || value > 14)
258                                         throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
259
260                                 state_image_index = value;
261                         }
262                 }
263
264                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
265                 public ListViewSubItemCollection SubItems {
266                         get { return sub_items; }
267                 }
268
269                 [Bindable (true)]
270                 [DefaultValue (null)]
271                 [Localizable (false)]
272                 [TypeConverter (typeof (StringConverter))]
273                 public object Tag {
274                         get { return tag; }
275                         set { tag = value; }
276                 }
277
278                 [Localizable (true)]
279                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
280                 public string Text {
281                         get {
282                                 if (this.sub_items.Count > 0)
283                                         return this.sub_items [0].Text;
284                                 else
285                                         return "";
286                         }
287                         set { this.sub_items [0].Text = value; }
288                 }
289
290                 [DefaultValue (true)]
291                 public bool UseItemStyleForSubItems {
292                         get { return use_item_style; }
293                         set { use_item_style = value; }
294                 }
295                 #endregion      // Public Instance Properties
296
297                 #region Public Instance Methods
298                 public void BeginEdit ()
299                 {
300                         // FIXME: TODO
301                         // if (owner != null && owner.LabelEdit 
302                         //    && owner.Activation == ItemActivation.Standard)
303                         // allow editing
304                         // else
305                         // throw new InvalidOperationException ();
306                 }
307
308                 public virtual object Clone ()
309                 {
310                         ListViewItem clone = new ListViewItem ();
311                         clone.back_color = this.BackColor;
312                         clone.font = this.Font;
313                         clone.fore_color = this.ForeColor;
314                         clone.image_index = this.image_index;
315                         clone.is_checked = this.is_checked;
316                         clone.is_focused = this.is_focused;
317                         clone.selected = this.selected;
318                         clone.state_image_index = this.state_image_index;
319                         clone.sub_items = new ListViewSubItemCollection (this);
320                         foreach (ListViewSubItem subItem in this.sub_items)
321                                 clone.sub_items.Add (subItem.Text, subItem.ForeColor,
322                                                      subItem.BackColor, subItem.Font);
323                         clone.tag = this.tag;
324                         clone.use_item_style = this.use_item_style;
325                         clone.owner = null;
326
327                         return clone;
328                 }
329
330                 public virtual void EnsureVisible ()
331                 {
332                         if (this.owner != null) {
333                                 owner.EnsureVisible (owner.Items.IndexOf (this));
334                         }
335                 }
336
337                 public Rectangle GetBounds (ItemBoundsPortion portion)
338                 {
339                         if (owner == null)
340                                 return Rectangle.Empty;
341                         
342                         // should we check for dirty flag to optimize this ?
343                         CalcListViewItem ();
344
345                         switch (portion) {
346
347                         case ItemBoundsPortion.Icon:
348                                 return icon_rect;
349
350                         case ItemBoundsPortion.Label:
351                                 return label_rect;
352
353                         case ItemBoundsPortion.ItemOnly:
354                                 return item_rect;
355
356                         case ItemBoundsPortion.Entire:
357                                 return entire_rect;
358
359                         default:
360                                 throw new ArgumentException ("Invalid value for portion.");
361                         }
362                 }
363
364                 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
365                 {
366                         // FIXME: TODO
367                 }
368
369                 public virtual void Remove ()
370                 {
371                         if (owner != null)
372                                 owner.Items.Remove (this);
373                         owner = null;
374                 }
375
376                 public override string ToString ()
377                 {
378                         return string.Format ("ListViewItem: {{0}}", this.Text);
379                 }
380                 #endregion      // Public Instance Methods
381
382                 #region Protected Methods
383                 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
384                 {
385                         // FIXME: TODO
386                 }
387
388                 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
389                 {
390                         // FIXME: TODO
391                 }
392                 #endregion      // Protected Methods
393
394                 #region Private Internal Methods
395                 internal Rectangle CheckRect {
396                         get { return this.checkbox_rect; }
397                 }
398
399                 internal Rectangle EntireRect {
400                         get { return this.entire_rect; }
401                 }
402
403                 internal Rectangle IconRect {
404                         get { return this.icon_rect; }
405                 }
406
407                 internal Rectangle LabelRect {
408                         get { return this.label_rect; }
409                 }
410
411                 internal void CalcListViewItem ()
412                 {
413                         int item_ht;
414                         Size text_size = owner.text_size;
415                         
416                         if (owner.CheckBoxes)
417                                 checkbox_rect.Size = owner.CheckBoxSize;
418                         else
419                                 checkbox_rect = Rectangle.Empty;
420
421                         checkbox_rect.Location = this.location;
422
423                         switch (owner.View) {
424
425                         case View.Details:
426                                 // LAMESPEC: MSDN says, "In all views except the details
427                                 // view of the ListView, this value specifies the same
428                                 // bounding rectangle as the Entire value." Actually, it
429                                 // returns same bounding rectangles for Item and Entire
430                                 // values in the case of Details view.
431
432                                 icon_rect.X = checkbox_rect.X + checkbox_rect.Width + 2;
433                                 icon_rect.Y = checkbox_rect.Y;
434
435                                 item_ht = Math.Max (owner.CheckBoxSize.Height + 1,
436                                                     text_size.Height);
437
438                                 if (owner.SmallImageList != null) {
439                                         item_ht = Math.Max (item_ht,
440                                                             owner.SmallImageList.ImageSize.Height + 1);
441                                         icon_rect.Width = owner.SmallImageList.ImageSize.Width;
442                                 }
443                                 else
444                                         icon_rect.Width = 0;
445
446                                 label_rect.Height = checkbox_rect.Height = icon_rect.Height = item_ht;
447
448                                 label_rect.X = icon_rect.X + icon_rect.Width;
449                                 label_rect.Y = icon_rect.Y;
450
451                                 if (owner.Columns.Count > 0)
452                                         label_rect.Width = Math.Max (text_size.Width, owner.Columns[0].Wd);
453                                 else
454                                         label_rect.Width = text_size.Width;
455
456                                 item_rect = entire_rect = Rectangle.Union
457                                         (Rectangle.Union (checkbox_rect, icon_rect), label_rect);
458
459                                 // Take into account the rest of columns. First column
460                                 // is already taken into account above.
461                                 for (int i = 1; i < owner.Columns.Count; i++) {
462                                         item_rect.Width += owner.Columns [i].Wd;
463                                         entire_rect.Width += owner.Columns [i].Wd;
464                                 }
465                                 break;
466
467                         case View.LargeIcon:
468                                 if (owner.LargeImageList != null) {
469                                         icon_rect.Width = owner.LargeImageList.ImageSize.Width + 16;
470                                         icon_rect.Height = owner.LargeImageList.ImageSize.Height + 4;
471                                 }
472                                 else {
473                                         icon_rect.Width = 16;
474                                         icon_rect.Height = 4;
475                                 }
476
477                                 if (text_size.Width <= (checkbox_rect.Width + icon_rect.Width)) {
478                                         icon_rect.X = checkbox_rect.X + checkbox_rect.Width;
479                                         icon_rect.Y = checkbox_rect.Y;
480
481                                         label_rect.X = icon_rect.X + (icon_rect.Width 
482                                                                       - text_size.Width) / 2;
483                                         label_rect.Y = Math.Max (checkbox_rect.Bottom,
484                                                                  icon_rect.Bottom) + 2;
485                                         label_rect.Size = text_size;
486                                 }
487                                 else {
488                                         label_rect.X = this.location.X;
489
490                                         int centerX = label_rect.X + text_size.Width / 2;
491                                         icon_rect.X = centerX - icon_rect.Width / 2;
492                                         checkbox_rect.X = (icon_rect.X - checkbox_rect.Width);
493
494                                         icon_rect.Y = checkbox_rect.Y;
495
496                                         label_rect.Y = Math.Max (checkbox_rect.Bottom,
497                                                                  icon_rect.Bottom) + 2;
498                                         label_rect.Size = text_size;
499                                 }
500
501                                 item_rect = Rectangle.Union (icon_rect, label_rect);
502                                 entire_rect = Rectangle.Union (item_rect, checkbox_rect);
503                                 break;
504
505                         case View.List:
506                                         goto case View.SmallIcon;
507
508                         case View.SmallIcon:
509                                 icon_rect.X = checkbox_rect.X + checkbox_rect.Width;
510                                 icon_rect.Y = checkbox_rect.Y;
511
512                                 item_ht = Math.Max (owner.CheckBoxSize.Height, text_size.Height);
513
514                                 if (owner.SmallImageList != null) {
515                                         item_ht = Math.Max (item_ht,
516                                                             owner.SmallImageList.ImageSize.Height + 1);
517                                         icon_rect.Width = owner.SmallImageList.ImageSize.Width;
518                                 }
519                                 else
520                                         icon_rect.Width = 0;
521
522                                 label_rect.Height = checkbox_rect.Height = icon_rect.Height = item_ht;
523
524                                 label_rect.X = icon_rect.X + icon_rect.Width;
525                                 label_rect.Y = icon_rect.Y;
526                                 label_rect.Width = text_size.Width;
527
528                                 item_rect = Rectangle.Union (icon_rect, label_rect);
529                                 entire_rect = Rectangle.Union (item_rect, checkbox_rect);
530                                 break;
531                         }
532                 }
533                 #endregion      // Private Internal Methods
534
535                 #region Subclasses
536
537                 [DefaultProperty ("Text")]
538                 [DesignTimeVisible (false)]
539                 [Serializable]
540                 [ToolboxItem (false)]
541                 [TypeConverter (typeof(ListViewSubItemConverter))]
542                 public class ListViewSubItem
543                 {
544                         private Color back_color;
545                         private Font font;
546                         private Color fore_color;
547                         internal ListViewItem owner;
548                         private string text;
549                         
550                         #region Public Constructors
551                         public ListViewSubItem ()
552                         {
553                         }
554
555                         public ListViewSubItem (ListViewItem owner, string text)
556                                 : this (owner, text, ThemeEngine.Current.ColorWindowText,
557                                         ThemeEngine.Current.ColorWindow,
558                                         ThemeEngine.Current.DefaultFont)
559                         {
560                         }
561
562                         public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
563                                                 Color backColor, Font font)
564                         {
565                                 this.owner = owner;
566                                 this.text = text;
567                                 this.fore_color = foreColor;
568                                 this.back_color = backColor;
569                                 this.font = font;
570                         }
571                         #endregion // Public Constructors
572
573                         #region Public Instance Properties
574                         public Color BackColor {
575                                 get { return back_color; }
576                                 set { back_color = value; }
577                         }
578
579                         [Localizable (true)]
580                         public Font Font {
581                                 get {
582                                         if (font != null)
583                                                 return font;
584                                         else if (owner != null)
585                                                 return owner.Font;
586                                         return font;
587                                 }
588                                 set { font = value; }
589                         }
590
591                         public Color ForeColor {
592                                 get { return fore_color; }
593                                 set { fore_color = value; }
594                         }
595
596                         [Localizable (true)]
597                         public string Text {
598                                 get { return text; }
599                                 set { text = value; }
600                         }
601                         #endregion // Public Instance Properties
602
603                         #region Public Methods
604                         public void ResetStyle ()
605                         {
606                                 font = ThemeEngine.Current.DefaultFont;
607                                 back_color = ThemeEngine.Current.DefaultControlBackColor;
608                                 fore_color = ThemeEngine.Current.DefaultControlForeColor;
609                         }
610
611                         public override string ToString ()
612                         {
613                                 return string.Format ("ListViewSubItem {{0}}", text);
614                         }
615                         #endregion // Public Methods
616                 }
617
618                 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
619                 {
620                         private ArrayList list;
621                         internal ListViewItem owner;
622
623                         #region Public Constructors
624                         public ListViewSubItemCollection (ListViewItem owner)
625                         {
626                                 this.owner = owner;
627                                 this.list = new ArrayList ();
628                         }
629                         #endregion // Public Constructors
630
631                         #region Public Properties
632                         [Browsable (false)]
633                         public virtual int Count {
634                                 get { return list.Count; }
635                         }
636
637                         public virtual bool IsReadOnly {
638                                 get { return false; }
639                         }
640
641                         public ListViewSubItem this [int index] {
642                                 get { return (ListViewSubItem) list [index]; }
643                                 set { 
644                                         value.owner = this.owner;
645                                         list [index] = value;
646                                 }
647                         }
648
649                         bool ICollection.IsSynchronized {
650                                 get { return list.IsSynchronized; }
651                         }
652
653                         object ICollection.SyncRoot {
654                                 get { return list.SyncRoot; }
655                         }
656
657                         bool IList.IsFixedSize {
658                                 get { return list.IsFixedSize; }
659                         }
660
661                         object IList.this [int index] {
662                                 get { return this [index]; }
663                                 set {
664                                         if (! (value is ListViewSubItem))
665                                                 throw new ArgumentException ("Not of type ListViewSubItem", "value");
666                                         this [index] = (ListViewSubItem) value;
667                                 }
668                         }
669                         #endregion // Public Properties
670
671                         #region Public Methods
672                         public ListViewSubItem Add (ListViewSubItem item)
673                         {
674                                 item.owner = this.owner;
675                                 list.Add (item);
676                                 return item;
677                         }
678
679                         public ListViewSubItem Add (string text)
680                         {
681                                 ListViewSubItem item = new ListViewSubItem (this.owner, text);
682                                 list.Add (item);
683                                 return item;
684                         }
685
686                         public ListViewSubItem Add (string text, Color foreColor,
687                                                     Color backColor, Font font)
688                         {
689                                 ListViewSubItem item = new ListViewSubItem (this.owner, text,
690                                                                             foreColor, backColor, font);
691                                 list.Add (item);
692                                 return item;
693                         }
694
695                         public void AddRange (ListViewSubItem [] items)
696                         {
697                                 this.Clear ();
698                                 foreach (ListViewSubItem item in items)
699                                         this.Add (item);
700                         }
701
702                         public void AddRange (string [] items)
703                         {
704                                 this.Clear ();
705                                 foreach (string item in items)
706                                         this.Add (item);
707                         }
708
709                         public void AddRange (string [] items, Color foreColor,
710                                               Color backColor, Font font)
711                         {
712                                 this.Clear ();
713                                 foreach (string item in items)
714                                         this.Add (item, foreColor, backColor, font);
715                         }
716
717                         public virtual void Clear ()
718                         {
719                                 list.Clear ();
720                         }
721
722                         public bool Contains (ListViewSubItem item)
723                         {
724                                 return list.Contains (item);
725                         }
726
727                         public virtual IEnumerator GetEnumerator ()
728                         {
729                                 return list.GetEnumerator ();
730                         }
731
732                         void ICollection.CopyTo (Array dest, int index)
733                         {
734                                 list.CopyTo (dest, index);
735                         }
736
737                         int IList.Add (object item)
738                         {
739                                 if (! (item is ListViewSubItem)) {
740                                         throw new ArgumentException ("Not of type ListViewSubItem", "item");
741                                 }
742
743                                 ListViewSubItem sub_item = (ListViewSubItem) item;
744                                 sub_item.owner = this.owner;
745                                 return list.Add (sub_item);
746                         }
747
748                         bool IList.Contains (object subItem)
749                         {
750                                 if (! (subItem is ListViewSubItem)) {
751                                         throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
752                                 }
753
754                                 return this.Contains ((ListViewSubItem) subItem);
755                         }
756
757                         int IList.IndexOf (object subItem)
758                         {
759                                 if (! (subItem is ListViewSubItem)) {
760                                         throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
761                                 }
762
763                                 return this.IndexOf ((ListViewSubItem) subItem);
764                         }
765
766                         void IList.Insert (int index, object item)
767                         {
768                                 if (! (item is ListViewSubItem)) {
769                                         throw new ArgumentException ("Not of type ListViewSubItem", "item");
770                                 }
771
772                                 this.Insert (index, (ListViewSubItem) item);
773                         }
774
775                         void IList.Remove (object item)
776                         {
777                                 if (! (item is ListViewSubItem)) {
778                                         throw new ArgumentException ("Not of type ListViewSubItem", "item");
779                                 }
780
781                                 this.Remove ((ListViewSubItem) item);
782                         }
783
784                         public int IndexOf (ListViewSubItem subItem)
785                         {
786                                 return list.IndexOf (subItem);
787                         }
788
789                         public void Insert (int index, ListViewSubItem item)
790                         {
791                                 item.owner = this.owner;
792                                 list.Insert (index, item);
793                         }
794
795                         public void Remove (ListViewSubItem item)
796                         {
797                                 list.Remove (item);
798                         }
799
800                         public virtual void RemoveAt (int index)
801                         {
802                                 list.RemoveAt (index);
803                         }
804                         #endregion // Public Methods
805                 }
806                 #endregion // Subclasses
807         }
808 }