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