1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
23 // Ravindra (rkumar@novell.com)
24 // Mike Kestner <mkestner@novell.com>
25 // Daniel Nauck (dna(at)mono-project(dot)de)
27 using System
.Collections
;
28 using System
.ComponentModel
;
30 using System
.Runtime
.Serialization
;
32 namespace System
.Windows
.Forms
34 [DefaultProperty ("Text")]
35 [DesignTimeVisible (false)]
38 [TypeConverter (typeof (ListViewItemConverter
))]
39 public class ListViewItem
: ICloneable
, ISerializable
41 #region Instance Variables
42 private int image_index
= -1;
43 private bool is_checked
= false;
44 private bool is_focused
= false;
45 private int state_image_index
= -1;
46 private ListViewSubItemCollection sub_items
;
48 private bool use_item_style
= true;
50 private ListViewGroup
group = null;
51 private string name
= String
.Empty
;
52 private string image_key
= String
.Empty
;
53 int index
; // cached index for VirtualMode
56 Rectangle checkbox_rect
; // calculated by CalcListViewItem method
67 #endregion Instance Variables
69 #region Public Constructors
70 public ListViewItem ()
72 this.sub_items
= new ListViewSubItemCollection (this);
73 this.sub_items
.Add ("");
76 public ListViewItem (string text
) : this (text
, -1)
80 public ListViewItem (string [] items
) : this (items
, -1)
84 public ListViewItem (ListViewItem
.ListViewSubItem
[] subItems
, int imageIndex
)
86 this.sub_items
= new ListViewSubItemCollection (this);
87 this.sub_items
.AddRange (subItems
);
88 this.image_index
= imageIndex
;
91 public ListViewItem (string text
, int imageIndex
)
93 this.image_index
= imageIndex
;
94 this.sub_items
= new ListViewSubItemCollection (this);
95 this.sub_items
.Add (text
);
98 public ListViewItem (string [] items
, int imageIndex
)
100 this.sub_items
= new ListViewSubItemCollection (this);
101 this.sub_items
.AddRange (items
);
102 this.image_index
= imageIndex
;
105 public ListViewItem (string [] items
, int imageIndex
, Color foreColor
,
106 Color backColor
, Font font
)
108 this.sub_items
= new ListViewSubItemCollection (this);
109 this.sub_items
.AddRange (items
);
110 this.image_index
= 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
) : this()
129 this.sub_items
.AddRange(subItems
);
130 this.ImageKey
= imageKey
;
133 public ListViewItem(string[] items
, string imageKey
, Color foreColor
,
134 Color backColor
, Font font
) : this()
136 this.sub_items
= new ListViewSubItemCollection(this);
137 this.sub_items
.AddRange(items
);
138 ForeColor
= foreColor
;
139 BackColor
= backColor
;
141 this.ImageKey
= imageKey
;
144 public ListViewItem(ListViewGroup
group) : this()
149 public ListViewItem(string text
, ListViewGroup
group) : this(text
)
154 public ListViewItem(string[] items
, ListViewGroup
group) : this(items
)
159 public ListViewItem(ListViewSubItem
[] subItems
, int imageIndex
, ListViewGroup
group)
160 : this(subItems
, imageIndex
)
165 public ListViewItem(ListViewSubItem
[] subItems
, string imageKey
, ListViewGroup
group)
166 : this(subItems
, imageKey
)
171 public ListViewItem(string text
, int imageIndex
, ListViewGroup
group)
172 : this(text
, imageIndex
)
177 public ListViewItem(string text
, string imageKey
, ListViewGroup
group)
178 : this(text
, imageKey
)
183 public ListViewItem(string[] items
, int imageIndex
, ListViewGroup
group)
184 : this(items
, imageIndex
)
189 public ListViewItem(string[] items
, string imageKey
, ListViewGroup
group)
190 : this(items
, imageKey
)
195 public ListViewItem(string[] items
, int imageIndex
, Color foreColor
, Color backColor
,
196 Font font
, ListViewGroup
group)
197 : this(items
, imageIndex
, foreColor
, backColor
, font
)
202 public ListViewItem(string[] items
, string imageKey
, Color foreColor
, Color backColor
,
203 Font font
, ListViewGroup
group)
204 : this(items
, imageKey
, foreColor
, backColor
, font
)
209 #endregion // Public Constructors
211 #region Public Instance Properties
212 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
213 public Color BackColor
{
215 if (sub_items
.Count
> 0)
216 return sub_items
[0].BackColor
;
219 return owner
.BackColor
;
221 return ThemeEngine
.Current
.ColorWindow
;
224 set { sub_items[0].BackColor = value; }
228 public Rectangle Bounds
{
230 return GetBounds (ItemBoundsPortion
.Entire
);
234 [DefaultValue (false)]
235 [RefreshProperties (RefreshProperties
.Repaint
)]
236 public bool Checked
{
237 get { return is_checked; }
239 if (is_checked
== value)
243 CheckState current_value
= is_checked
? CheckState
.Checked
: CheckState
.Unchecked
;
244 CheckState new_value
= value ? CheckState
.Checked
: CheckState
.Unchecked
;
246 ItemCheckEventArgs icea
= new ItemCheckEventArgs (Index
,
247 new_value
, current_value
);
248 owner
.OnItemCheck (icea
);
250 if (new_value
!= current_value
) {
251 // force re-population of list
252 owner
.CheckedItems
.Reset ();
253 is_checked
= new_value
== CheckState
.Checked
;
257 ItemCheckedEventArgs args
= new ItemCheckedEventArgs (this);
258 owner
.OnItemChecked (args
);
267 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
268 public bool Focused
{
269 get { return is_focused; }
271 if (is_focused
== value)
284 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
289 else if (owner
!= null)
292 return ThemeEngine
.Current
.DefaultFont
;
306 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
307 public Color ForeColor
{
309 if (sub_items
.Count
> 0)
310 return sub_items
[0].ForeColor
;
313 return owner
.ForeColor
;
315 return ThemeEngine
.Current
.ColorWindowText
;
317 set { sub_items[0].ForeColor = value; }
321 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
322 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts
.AssemblySystem_Design
,
323 typeof (System
.Drawing
.Design
.UITypeEditor
))]
326 [RefreshProperties (RefreshProperties
.Repaint
)]
327 // [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
329 [TypeConverter (typeof (ImageIndexConverter
))]
331 public int ImageIndex
{
332 get { return image_index; }
335 throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
339 image_key
= String
.Empty
;
350 [LocalizableAttribute (true)]
351 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
352 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts
.AssemblySystem_Design
,
353 typeof (System
.Drawing
.Design
.UITypeEditor
))]
354 [RefreshProperties (RefreshProperties
.Repaint
)]
355 // XXX [TypeConverter (typeof (ImageKeyConverter))
356 public string ImageKey
{
361 image_key
= value == null ? String
.Empty
: value;
372 public ImageList ImageList
{
376 else if (owner
.View
== View
.LargeIcon
)
377 return owner
.large_image_list
;
379 return owner
.small_image_list
;
389 if (owner
.VirtualMode
)
393 return owner
.Items
.IndexOf (this);
398 public ListView ListView
{
399 get { return owner; }
405 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
411 name
= value == null ? String
.Empty
: value;
417 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
418 public bool Selected
{
423 if (selected
== value)
427 if (value && !owner
.MultiSelect
)
428 owner
.SelectedItems
.Clear ();
430 // force re-population of list
431 owner
.SelectedIndices
.Reset ();
433 owner
.OnSelectedIndexChanged ();
442 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts
.AssemblySystem_Design
,
443 typeof (System
.Drawing
.Design
.UITypeEditor
))]
446 [RefreshProperties (RefreshProperties
.Repaint
)]
447 // XXX [RelatedImageListAttribute ("ListView.StateImageList")]
448 // XXX [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
450 [TypeConverter (typeof (ImageIndexConverter
))]
452 public int StateImageIndex
{
453 get { return state_image_index; }
455 if (value < -1 || value > 14)
456 throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
458 state_image_index
= value;
462 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
464 [Editor ("System.Windows.Forms.Design.ListViewSubItemCollectionEditor, " + Consts
.AssemblySystem_Design
,
465 typeof (System
.Drawing
.Design
.UITypeEditor
))]
467 public ListViewSubItemCollection SubItems
{
468 get { return sub_items; }
472 [DefaultValue (null)]
473 [Localizable (false)]
474 [TypeConverter (typeof (StringConverter
))]
481 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
484 if (this.sub_items
.Count
> 0)
485 return this.sub_items
[0].Text
;
490 if (sub_items
[0].Text
== value)
493 sub_items
[0].Text
= value;
501 [DefaultValue (true)]
502 public bool UseItemStyleForSubItems
{
503 get { return use_item_style; }
504 set { use_item_style = value; }
508 [LocalizableAttribute(true)]
509 [DefaultValue (null)]
510 public ListViewGroup Group
{
511 get { return this.group; }
514 if (this.group != value)
518 value.Items
.Add(this);
520 if (this.group != null)
521 this.group.Items
.Remove(this);
527 if(this.group != null)
528 this.group.Items
.Remove(this);
535 #endregion // Public Instance Properties
537 #region Public Instance Methods
538 public void BeginEdit ()
540 if (owner
!= null && owner
.LabelEdit
) {
541 owner
.item_control
.BeginEdit (this);
544 // if (owner != null && owner.LabelEdit
545 // && owner.Activation == ItemActivation.Standard)
548 // throw new InvalidOperationException ();
551 public virtual object Clone ()
553 ListViewItem clone
= new ListViewItem ();
554 clone
.image_index
= this.image_index
;
555 clone
.is_checked
= this.is_checked
;
556 clone
.is_focused
= this.is_focused
;
557 clone
.selected
= this.selected
;
558 clone
.font
= this.font
;
559 clone
.state_image_index
= this.state_image_index
;
560 clone
.sub_items
= new ListViewSubItemCollection (this);
562 foreach (ListViewSubItem subItem
in this.sub_items
)
563 clone
.sub_items
.Add (subItem
.Text
, subItem
.ForeColor
,
564 subItem
.BackColor
, subItem
.Font
);
565 clone
.tag
= this.tag
;
566 clone
.use_item_style
= this.use_item_style
;
575 public virtual void EnsureVisible ()
577 if (this.owner
!= null) {
578 owner
.EnsureVisible (owner
.Items
.IndexOf (this));
582 public Rectangle
GetBounds (ItemBoundsPortion portion
)
585 return Rectangle
.Empty
;
590 case ItemBoundsPortion
.Icon
:
594 case ItemBoundsPortion
.Label
:
598 case ItemBoundsPortion
.ItemOnly
:
602 case ItemBoundsPortion
.Entire
:
607 throw new ArgumentException ("Invalid value for portion.");
610 Point item_loc
= owner
.GetItemLocation (Index
);
611 rect
.X
+= item_loc
.X
;
612 rect
.Y
+= item_loc
.Y
;
616 void ISerializable
.GetObjectData (SerializationInfo info
, StreamingContext context
)
621 public virtual void Remove ()
626 owner
.item_control
.CancelEdit (this);
627 owner
.Items
.Remove (this);
631 public override string ToString ()
633 return string.Format ("ListViewItem: {0}", this.Text
);
635 #endregion // Public Instance Methods
637 #region Protected Methods
638 protected virtual void Deserialize (SerializationInfo info
, StreamingContext context
)
643 protected virtual void Serialize (SerializationInfo info
, StreamingContext context
)
647 #endregion // Protected Methods
649 #region Private Internal Methods
650 internal Rectangle CheckRectReal
{
652 Rectangle rect
= checkbox_rect
;
653 Point item_loc
= owner
.GetItemLocation (Index
);
654 rect
.X
+= item_loc
.X
;
655 rect
.Y
+= item_loc
.Y
;
660 internal ListView Owner
{
670 internal void SetIndex (int index
)
676 private void Invalidate ()
678 if (owner
== null || owner
.item_control
== null)
681 owner
.item_control
.Invalidate (Bounds
);
684 internal void Layout ()
688 Size text_size
= owner
.text_size
;
690 checkbox_rect
= Rectangle
.Empty
;
691 if (owner
.CheckBoxes
)
692 checkbox_rect
.Size
= owner
.CheckBoxSize
;
694 switch (owner
.View
) {
696 // LAMESPEC: MSDN says, "In all views except the details
697 // view of the ListView, this value specifies the same
698 // bounding rectangle as the Entire value." Actually, it
699 // returns same bounding rectangles for Item and Entire
700 // values in the case of Details view.
702 icon_rect
= label_rect
= Rectangle
.Empty
;
703 icon_rect
.X
= checkbox_rect
.Width
+ 2;
704 item_ht
= owner
.ItemSize
.Height
;
706 if (owner
.SmallImageList
!= null)
707 icon_rect
.Width
= owner
.SmallImageList
.ImageSize
.Width
;
709 label_rect
.Height
= icon_rect
.Height
= item_ht
;
710 checkbox_rect
.Y
= item_ht
- checkbox_rect
.Height
;
712 label_rect
.X
= icon_rect
.Right
+ 1;
714 if (owner
.Columns
.Count
> 0)
715 label_rect
.Width
= owner
.Columns
[0].Wd
- label_rect
.X
;
717 label_rect
.Width
= text_size
.Width
;
719 item_rect
= total
= Rectangle
.Union
720 (Rectangle
.Union (checkbox_rect
, icon_rect
), label_rect
);
721 bounds
.Size
= total
.Size
;
723 // Take into account the rest of columns. First column
724 // is already taken into account above.
725 for (int i
= 1; i
< owner
.Columns
.Count
; i
++) {
726 item_rect
.Width
+= owner
.Columns
[i
].Wd
;
727 bounds
.Width
+= owner
.Columns
[i
].Wd
;
732 label_rect
= icon_rect
= Rectangle
.Empty
;
734 SizeF sz
= owner
.DeviceContext
.MeasureString (Text
, Font
);
735 if ((int) sz
.Width
> text_size
.Width
) {
737 int text_width
= text_size
.Width
;
738 StringFormat format
= new StringFormat ();
739 format
.Alignment
= StringAlignment
.Center
;
740 sz
= owner
.DeviceContext
.MeasureString (Text
, Font
, text_width
, format
);
741 text_size
.Height
= (int) sz
.Height
;
743 text_size
.Height
= 2 * (int) sz
.Height
;
746 if (owner
.LargeImageList
!= null) {
747 icon_rect
.Width
= owner
.LargeImageList
.ImageSize
.Width
;
748 icon_rect
.Height
= owner
.LargeImageList
.ImageSize
.Height
;
751 if (checkbox_rect
.Height
> icon_rect
.Height
)
752 icon_rect
.Y
= checkbox_rect
.Height
- icon_rect
.Height
;
754 checkbox_rect
.Y
= icon_rect
.Height
- checkbox_rect
.Height
;
756 if (text_size
.Width
<= icon_rect
.Width
) {
757 icon_rect
.X
= checkbox_rect
.Width
+ 1;
758 label_rect
.X
= icon_rect
.X
+ (icon_rect
.Width
- text_size
.Width
) / 2;
759 label_rect
.Y
= icon_rect
.Bottom
+ 2;
760 label_rect
.Size
= text_size
;
762 int centerX
= text_size
.Width
/ 2;
763 icon_rect
.X
= checkbox_rect
.Width
+ 1 + centerX
- icon_rect
.Width
/ 2;
764 label_rect
.X
= checkbox_rect
.Width
+ 1;
765 label_rect
.Y
= icon_rect
.Bottom
+ 2;
766 label_rect
.Size
= text_size
;
769 item_rect
= Rectangle
.Union (icon_rect
, label_rect
);
770 total
= Rectangle
.Union (item_rect
, checkbox_rect
);
771 bounds
.Size
= total
.Size
;
776 label_rect
= icon_rect
= Rectangle
.Empty
;
777 icon_rect
.X
= checkbox_rect
.Width
+ 1;
778 item_ht
= Math
.Max (owner
.CheckBoxSize
.Height
, text_size
.Height
);
780 if (owner
.SmallImageList
!= null) {
781 item_ht
= Math
.Max (item_ht
, owner
.SmallImageList
.ImageSize
.Height
);
782 icon_rect
.Width
= owner
.SmallImageList
.ImageSize
.Width
;
783 icon_rect
.Height
= owner
.SmallImageList
.ImageSize
.Height
;
786 checkbox_rect
.Y
= item_ht
- checkbox_rect
.Height
;
787 label_rect
.X
= icon_rect
.Right
+ 1;
788 label_rect
.Width
= text_size
.Width
;
789 label_rect
.Height
= icon_rect
.Height
= item_ht
;
791 item_rect
= Rectangle
.Union (icon_rect
, label_rect
);
792 total
= Rectangle
.Union (item_rect
, checkbox_rect
);
793 bounds
.Size
= total
.Size
;
797 label_rect
= icon_rect
= Rectangle
.Empty
;
799 if (owner
.LargeImageList
!= null) {
800 icon_rect
.Width
= owner
.LargeImageList
.ImageSize
.Width
;
801 icon_rect
.Height
= owner
.LargeImageList
.ImageSize
.Height
;
805 SizeF tsize
= owner
.DeviceContext
.MeasureString (Text
, Font
);
807 // Set initial values for subitem's layout
808 int total_height
= (int)Math
.Ceiling (tsize
.Height
);
809 int max_subitem_width
= (int)Math
.Ceiling (tsize
.Width
);
810 SubItems
[0].bounds
.Height
= total_height
;
812 int count
= Math
.Min (owner
.Columns
.Count
, SubItems
.Count
);
813 for (int i
= 1; i
< count
; i
++) { // Ignore first column and first subitem
814 ListViewSubItem sub_item
= SubItems
[i
];
815 if (sub_item
.Text
== null || sub_item
.Text
.Length
== 0)
818 tsize
= owner
.DeviceContext
.MeasureString (sub_item
.Text
, sub_item
.Font
);
820 int width
= (int)Math
.Ceiling (tsize
.Width
);
822 if (width
> max_subitem_width
)
823 max_subitem_width
= width
;
825 int height
= (int)Math
.Ceiling (tsize
.Height
);
826 total_height
+= height
+ separation
;
828 sub_item
.bounds
.Height
= height
;
832 label_rect
.X
= icon_rect
.Right
+ 4;
833 label_rect
.Y
= owner
.TileSize
.Height
/ 2 - total_height
/ 2;
834 label_rect
.Width
= max_subitem_width
;
835 label_rect
.Height
= total_height
;
837 // Second pass for assigning bounds. This time take first subitem into account.
838 int current_y
= label_rect
.Y
;
839 for (int j
= 0; j
< count
; j
++) {
840 ListViewSubItem sub_item
= SubItems
[j
];
841 if (sub_item
.Text
== null || sub_item
.Text
.Length
== 0)
844 sub_item
.SetBounds (label_rect
.X
, current_y
, max_subitem_width
, sub_item
.bounds
.Height
);
845 current_y
+= sub_item
.Bounds
.Height
+ separation
;
848 item_rect
= Rectangle
.Union (icon_rect
, label_rect
);
849 bounds
.Size
= item_rect
.Size
;
855 #endregion // Private Internal Methods
859 [DefaultProperty ("Text")]
860 [DesignTimeVisible (false)]
862 [ToolboxItem (false)]
863 [TypeConverter (typeof(ListViewSubItemConverter
))]
864 public class ListViewSubItem
866 private Color back_color
;
868 private Color fore_color
;
869 internal ListViewItem owner
;
870 private string text
= string.Empty
;
872 private string name
= String
.Empty
;
874 internal Rectangle bounds
;
877 #region Public Constructors
878 public ListViewSubItem ()
882 public ListViewSubItem (ListViewItem owner
, string text
)
883 : this (owner
, text
, ThemeEngine
.Current
.ColorWindowText
,
884 ThemeEngine
.Current
.ColorWindow
, null)
888 public ListViewSubItem (ListViewItem owner
, string text
, Color foreColor
,
889 Color backColor
, Font font
)
893 this.fore_color
= foreColor
;
894 this.back_color
= backColor
;
897 #endregion // Public Constructors
899 #region Public Instance Properties
900 public Color BackColor
{
901 get { return back_color; }
909 public Rectangle Bounds
{
911 Rectangle retval
= bounds
;
913 retval
.X
+= owner
.Bounds
.X
;
914 retval
.Y
+= owner
.Bounds
.Y
;
927 else if (owner
!= null)
929 return ThemeEngine
.Current
.DefaultFont
;
939 public Color ForeColor
{
940 get { return fore_color; }
954 name
= value == null ? String
.Empty
: value;
958 [TypeConverter (typeof (StringConverter
))]
959 [BindableAttribute (true)]
960 [DefaultValue (null)]
961 [Localizable (false)]
987 #endregion // Public Instance Properties
989 #region Public Methods
990 public void ResetStyle ()
992 font
= ThemeEngine
.Current
.DefaultFont
;
993 back_color
= ThemeEngine
.Current
.DefaultControlBackColor
;
994 fore_color
= ThemeEngine
.Current
.DefaultControlForeColor
;
998 public override string ToString ()
1000 return string.Format ("ListViewSubItem {{0}}", text
);
1002 #endregion // Public Methods
1005 #region Private Methods
1006 private void Invalidate ()
1008 if (owner
== null || owner
.owner
== null)
1011 owner
.owner
.Invalidate ();
1015 internal int Height
{
1017 return bounds
.Height
;
1021 internal void SetBounds (int x
, int y
, int width
, int height
)
1023 bounds
= new Rectangle (x
, y
, width
, height
);
1026 #endregion // Private Methods
1029 public class ListViewSubItemCollection
: IList
, ICollection
, IEnumerable
1031 private ArrayList list
;
1032 internal ListViewItem owner
;
1034 #region Public Constructors
1035 public ListViewSubItemCollection (ListViewItem owner
)
1038 this.list
= new ArrayList ();
1040 #endregion // Public Constructors
1042 #region Public Properties
1045 get { return list.Count; }
1048 public bool IsReadOnly
{
1049 get { return false; }
1052 public ListViewSubItem
this [int index
] {
1053 get { return (ListViewSubItem) list [index]; }
1055 value.owner
= this.owner
;
1056 list
[index
] = value;
1061 public virtual ListViewSubItem
this [string key
] {
1063 int idx
= IndexOfKey (key
);
1067 return (ListViewSubItem
) list
[idx
];
1072 bool ICollection
.IsSynchronized
{
1073 get { return list.IsSynchronized; }
1076 object ICollection
.SyncRoot
{
1077 get { return list.SyncRoot; }
1080 bool IList
.IsFixedSize
{
1081 get { return list.IsFixedSize; }
1084 object IList
.this [int index
] {
1085 get { return this [index]; }
1087 if (! (value is ListViewSubItem
))
1088 throw new ArgumentException ("Not of type ListViewSubItem", "value");
1089 this [index
] = (ListViewSubItem
) value;
1092 #endregion // Public Properties
1094 #region Public Methods
1095 public ListViewSubItem
Add (ListViewSubItem item
)
1097 item
.owner
= this.owner
;
1102 public ListViewSubItem
Add (string text
)
1104 ListViewSubItem item
= new ListViewSubItem (this.owner
, text
);
1109 public ListViewSubItem
Add (string text
, Color foreColor
,
1110 Color backColor
, Font font
)
1112 ListViewSubItem item
= new ListViewSubItem (this.owner
, text
,
1113 foreColor
, backColor
, font
);
1118 public void AddRange (ListViewSubItem
[] items
)
1121 throw new ArgumentNullException ("items");
1123 foreach (ListViewSubItem item
in items
) {
1130 public void AddRange (string [] items
)
1133 throw new ArgumentNullException ("items");
1135 foreach (string item
in items
) {
1142 public void AddRange (string [] items
, Color foreColor
,
1143 Color backColor
, Font font
)
1146 throw new ArgumentNullException ("items");
1148 foreach (string item
in items
) {
1151 this.Add (item
, foreColor
, backColor
, font
);
1155 public void Clear ()
1160 public bool Contains (ListViewSubItem item
)
1162 return list
.Contains (item
);
1166 public virtual bool ContainsKey (string key
)
1168 return IndexOfKey (key
) != -1;
1172 public IEnumerator
GetEnumerator ()
1174 return list
.GetEnumerator ();
1177 void ICollection
.CopyTo (Array dest
, int index
)
1179 list
.CopyTo (dest
, index
);
1182 int IList
.Add (object item
)
1184 if (! (item
is ListViewSubItem
)) {
1185 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1188 ListViewSubItem sub_item
= (ListViewSubItem
) item
;
1189 sub_item
.owner
= this.owner
;
1190 return list
.Add (sub_item
);
1193 bool IList
.Contains (object subItem
)
1195 if (! (subItem
is ListViewSubItem
)) {
1196 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1199 return this.Contains ((ListViewSubItem
) subItem
);
1202 int IList
.IndexOf (object subItem
)
1204 if (! (subItem
is ListViewSubItem
)) {
1205 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1208 return this.IndexOf ((ListViewSubItem
) subItem
);
1211 void IList
.Insert (int index
, object item
)
1213 if (! (item
is ListViewSubItem
)) {
1214 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1217 this.Insert (index
, (ListViewSubItem
) item
);
1220 void IList
.Remove (object item
)
1222 if (! (item
is ListViewSubItem
)) {
1223 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1226 this.Remove ((ListViewSubItem
) item
);
1229 public int IndexOf (ListViewSubItem subItem
)
1231 return list
.IndexOf (subItem
);
1235 public virtual int IndexOfKey (string key
)
1237 if (key
== null || key
.Length
== 0)
1240 for (int i
= 0; i
< list
.Count
; i
++) {
1241 ListViewSubItem l
= (ListViewSubItem
) list
[i
];
1242 if (String
.Compare (l
.Name
, key
, true) == 0)
1250 public void Insert (int index
, ListViewSubItem item
)
1252 item
.owner
= this.owner
;
1253 list
.Insert (index
, item
);
1256 public void Remove (ListViewSubItem item
)
1262 public virtual void RemoveByKey (string key
)
1264 int idx
= IndexOfKey (key
);
1270 public void RemoveAt (int index
)
1272 list
.RemoveAt (index
);
1274 #endregion // Public Methods
1276 #endregion // Subclasses