1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
23 // Ravindra (rkumar@novell.com)
24 // Mike Kestner <mkestner@novell.com>
25 // Daniel Nauck (dna(at)mono-project(dot)de)
27 using System.Collections;
28 using System.ComponentModel;
30 using System.Runtime.Serialization;
32 namespace System.Windows.Forms
34 [DefaultProperty ("Text")]
35 [DesignTimeVisible (false)]
38 [TypeConverter (typeof (ListViewItemConverter))]
39 public class ListViewItem : ICloneable, ISerializable
41 #region Instance Variables
42 private int image_index = -1;
43 private bool is_checked = false;
44 private bool is_focused = false;
45 private int state_image_index = -1;
46 private ListViewSubItemCollection sub_items;
48 private bool use_item_style = true;
50 private ListViewGroup group = null;
51 private string name = String.Empty;
52 private string image_key = String.Empty;
53 string tooltip_text = String.Empty;
54 int index; // cached index for VirtualMode
57 Rectangle checkbox_rect; // calculated by CalcListViewItem method
64 Font hot_font; // cached font for hot tracking
71 #endregion Instance Variables
73 #region Public Constructors
74 public ListViewItem () : this (string.Empty)
78 public ListViewItem (string text) : this (text, -1)
82 public ListViewItem (string [] items) : this (items, -1)
86 public ListViewItem (ListViewItem.ListViewSubItem [] subItems, int imageIndex)
88 this.sub_items = new ListViewSubItemCollection (this);
89 for (int i = 0; i < subItems.Length; i++)
90 sub_items.Add (subItems [i]);
91 this.image_index = imageIndex;
94 public ListViewItem (string text, int imageIndex)
96 this.image_index = imageIndex;
97 this.sub_items = new ListViewSubItemCollection (this);
98 this.sub_items.Add (text);
101 public ListViewItem (string [] items, int imageIndex)
103 this.sub_items = new ListViewSubItemCollection (this);
105 for (int i = 0; i < items.Length; i++)
106 sub_items.Add (new ListViewSubItem (this, items [i]));
108 this.image_index = imageIndex;
111 public ListViewItem (string [] items, int imageIndex, Color foreColor,
112 Color backColor, Font font) : this (items, imageIndex)
114 ForeColor = foreColor;
115 BackColor = backColor;
120 public ListViewItem(string[] items, string imageKey) : this(items)
122 this.ImageKey = imageKey;
125 public ListViewItem(string text, string imageKey) : this(text)
127 this.ImageKey = imageKey;
130 public ListViewItem(ListViewSubItem[] subItems, string imageKey)
132 this.sub_items = new ListViewSubItemCollection (this);
133 for (int i = 0; i < subItems.Length; i++)
134 this.sub_items.Add (subItems [i]);
135 this.ImageKey = imageKey;
138 public ListViewItem(string[] items, string imageKey, Color foreColor,
139 Color backColor, Font font) : this(items, imageKey)
141 ForeColor = foreColor;
142 BackColor = backColor;
146 public ListViewItem(ListViewGroup group) : this()
151 public ListViewItem(string text, ListViewGroup group) : this(text)
156 public ListViewItem(string[] items, ListViewGroup group) : this(items)
161 public ListViewItem(ListViewSubItem[] subItems, int imageIndex, ListViewGroup group)
162 : this(subItems, imageIndex)
167 public ListViewItem(ListViewSubItem[] subItems, string imageKey, ListViewGroup group)
168 : this(subItems, imageKey)
173 public ListViewItem(string text, int imageIndex, ListViewGroup group)
174 : this(text, imageIndex)
179 public ListViewItem(string text, string imageKey, ListViewGroup group)
180 : this(text, imageKey)
185 public ListViewItem(string[] items, int imageIndex, ListViewGroup group)
186 : this(items, imageIndex)
191 public ListViewItem(string[] items, string imageKey, ListViewGroup group)
192 : this(items, imageKey)
197 public ListViewItem(string[] items, int imageIndex, Color foreColor, Color backColor,
198 Font font, ListViewGroup group)
199 : this(items, imageIndex, foreColor, backColor, font)
204 public ListViewItem(string[] items, string imageKey, Color foreColor, Color backColor,
205 Font font, ListViewGroup group)
206 : this(items, imageKey, foreColor, backColor, font)
211 #endregion // Public Constructors
213 #region Public Instance Properties
214 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
215 public Color BackColor {
217 if (sub_items.Count > 0)
218 return sub_items[0].BackColor;
221 return owner.BackColor;
223 return ThemeEngine.Current.ColorWindow;
225 set { SubItems [0].BackColor = value; }
229 public Rectangle Bounds {
231 return GetBounds (ItemBoundsPortion.Entire);
235 [DefaultValue (false)]
236 [RefreshProperties (RefreshProperties.Repaint)]
237 public bool Checked {
238 get { return is_checked; }
240 if (is_checked == value)
244 CheckState current_value = is_checked ? CheckState.Checked : CheckState.Unchecked;
245 CheckState new_value = value ? CheckState.Checked : CheckState.Unchecked;
247 ItemCheckEventArgs icea = new ItemCheckEventArgs (Index,
248 new_value, current_value);
249 owner.OnItemCheck (icea);
251 if (new_value != current_value) {
252 // force re-population of list
253 owner.CheckedItems.Reset ();
254 is_checked = new_value == CheckState.Checked;
258 ItemCheckedEventArgs args = new ItemCheckedEventArgs (this);
259 owner.OnItemChecked (args);
268 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
269 public bool Focused {
272 // As well as selection state in VirtualMode,
273 // focus state is stored in the ListView
274 if (owner != null && owner.VirtualMode)
275 return Index == owner.focused_item_index;
280 if (is_focused == value)
284 if (owner.FocusedItem != null)
285 owner.FocusedItem.UpdateFocusedState (false);
287 owner.focused_item_index = value ? Index : -1;
290 UpdateFocusedState (value);
295 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
300 else if (owner != null)
303 return ThemeEngine.Current.DefaultFont;
320 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
321 public Color ForeColor {
323 if (sub_items.Count > 0)
324 return sub_items[0].ForeColor;
327 return owner.ForeColor;
329 return ThemeEngine.Current.ColorWindowText;
331 set { SubItems [0].ForeColor = value; }
335 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
336 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
337 typeof (System.Drawing.Design.UITypeEditor))]
340 [RefreshProperties (RefreshProperties.Repaint)]
341 // [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
343 [TypeConverter (typeof (ImageIndexConverter))]
345 public int ImageIndex {
346 get { return image_index; }
349 throw new ArgumentException ("Invalid ImageIndex. It must be greater than or equal to -1.");
353 image_key = String.Empty;
364 [LocalizableAttribute (true)]
365 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
366 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
367 typeof (System.Drawing.Design.UITypeEditor))]
368 [RefreshProperties (RefreshProperties.Repaint)]
369 // XXX [TypeConverter (typeof (ImageKeyConverter))
370 public string ImageKey {
375 image_key = value == null ? String.Empty : value;
386 public ImageList ImageList {
390 else if (owner.View == View.LargeIcon)
391 return owner.large_image_list;
393 return owner.small_image_list;
403 if (owner.VirtualMode)
407 return owner.Items.IndexOf (this);
412 public ListView ListView {
413 get { return owner; }
419 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
425 name = value == null ? String.Empty : value;
430 // When ListView uses VirtualMode, selection state info
431 // lives in the ListView, not in the item
433 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
434 public bool Selected {
437 if (owner != null && owner.VirtualMode)
438 return owner.SelectedIndices.Contains (Index);
445 if (selected == value && owner != null && !owner.VirtualMode)
447 if (selected == value)
452 if (value && !owner.MultiSelect)
453 owner.SelectedIndices.Clear ();
455 if (owner.VirtualMode)
457 owner.SelectedIndices.InsertIndex (Index);
459 owner.SelectedIndices.RemoveIndex (Index);
464 // force re-population of list
465 owner.SelectedIndices.Reset ();
467 owner.OnItemSelectionChanged (new ListViewItemSelectionChangedEventArgs (this, Index, value));
469 owner.OnSelectedIndexChanged ();
478 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design,
479 typeof (System.Drawing.Design.UITypeEditor))]
482 [RefreshProperties (RefreshProperties.Repaint)]
483 // XXX [RelatedImageListAttribute ("ListView.StateImageList")]
484 // XXX [TypeConverter (typeof (NoneExcludedImageIndexConverter))]
486 [TypeConverter (typeof (ImageIndexConverter))]
488 public int StateImageIndex {
489 get { return state_image_index; }
491 if (value < -1 || value > 14)
492 throw new ArgumentOutOfRangeException ("Invalid StateImageIndex. It must be in the range of [-1, 14].");
494 state_image_index = value;
498 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
500 [Editor ("System.Windows.Forms.Design.ListViewSubItemCollectionEditor, " + Consts.AssemblySystem_Design,
501 typeof (System.Drawing.Design.UITypeEditor))]
503 public ListViewSubItemCollection SubItems {
505 if (sub_items.Count == 0)
506 this.sub_items.Add (string.Empty);
512 [DefaultValue (null)]
513 [Localizable (false)]
514 [TypeConverter (typeof (StringConverter))]
521 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
524 if (this.sub_items.Count > 0)
525 return this.sub_items [0].Text;
530 if (SubItems [0].Text == value)
533 sub_items [0].Text = value;
541 [DefaultValue (true)]
542 public bool UseItemStyleForSubItems {
543 get { return use_item_style; }
544 set { use_item_style = value; }
548 [LocalizableAttribute(true)]
549 [DefaultValue (null)]
550 public ListViewGroup Group {
551 get { return this.group; }
553 if (group != value) {
555 group.Items.Remove (this);
557 value.Items.Add (this);
565 public string ToolTipText {
571 value = String.Empty;
573 tooltip_text = value;
578 #endregion // Public Instance Properties
580 #region Public Instance Methods
581 public void BeginEdit ()
583 if (owner != null && owner.LabelEdit) {
584 owner.item_control.BeginEdit (this);
587 // if (owner != null && owner.LabelEdit
588 // && owner.Activation == ItemActivation.Standard)
591 // throw new InvalidOperationException ();
594 public virtual object Clone ()
596 ListViewItem clone = new ListViewItem ();
597 clone.image_index = this.image_index;
598 clone.is_checked = this.is_checked;
599 clone.is_focused = this.is_focused;
600 clone.selected = this.selected;
601 clone.font = this.font;
602 clone.state_image_index = this.state_image_index;
603 clone.sub_items = new ListViewSubItemCollection (this);
605 foreach (ListViewSubItem subItem in this.sub_items)
606 clone.sub_items.Add (subItem.Text, subItem.ForeColor,
607 subItem.BackColor, subItem.Font);
608 clone.tag = this.tag;
609 clone.use_item_style = this.use_item_style;
613 clone.tooltip_text = tooltip_text;
619 public virtual void EnsureVisible ()
621 if (this.owner != null) {
622 owner.EnsureVisible (owner.Items.IndexOf (this));
626 public Rectangle GetBounds (ItemBoundsPortion portion)
629 return Rectangle.Empty;
634 // Can't cache bounds in Virtual mode,
635 // since we can get different item instances at each invocation
636 if (owner.VirtualMode)
640 case ItemBoundsPortion.Icon:
644 case ItemBoundsPortion.Label:
648 case ItemBoundsPortion.ItemOnly:
652 case ItemBoundsPortion.Entire:
657 throw new ArgumentException ("Invalid value for portion.");
660 Point item_loc = owner.GetItemLocation (Index);
661 rect.X += item_loc.X;
662 rect.Y += item_loc.Y;
666 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
672 public ListViewSubItem GetSubItemAt (int x, int y)
674 if (owner != null && owner.View != View.Details)
677 foreach (ListViewSubItem sub_item in sub_items)
678 if (sub_item.Bounds.Contains (x, y))
685 public virtual void Remove ()
690 owner.item_control.CancelEdit (this);
691 owner.Items.Remove (this);
695 public override string ToString ()
697 return string.Format ("ListViewItem: {0}", this.Text);
699 #endregion // Public Instance Methods
701 #region Protected Methods
702 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
707 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
711 #endregion // Protected Methods
713 #region Private Internal Methods
714 internal Rectangle CheckRectReal {
716 Rectangle rect = checkbox_rect;
717 Point item_loc = owner.GetItemLocation (Index);
718 rect.X += item_loc.X;
719 rect.Y += item_loc.Y;
724 Rectangle text_bounds;
725 internal Rectangle TextBounds {
727 Rectangle result = text_bounds;
728 Point loc = owner.GetItemLocation (Index);
738 return Index == owner.HotItemIndex;
742 internal Font HotFont {
744 if (hot_font == null)
745 hot_font = new Font (Font, Font.Style | FontStyle.Underline);
752 internal ListView Owner {
762 internal void SetIndex (int index)
767 internal void SetGroup (ListViewGroup group)
773 void UpdateFocusedState (bool is_focused)
775 this.is_focused = is_focused;
783 internal void Invalidate ()
785 if (owner == null || owner.item_control == null)
788 owner.item_control.Invalidate (Bounds);
791 internal void Layout ()
797 Size text_size = owner.text_size;
799 checkbox_rect = Rectangle.Empty;
800 if (owner.CheckBoxes)
801 checkbox_rect.Size = owner.CheckBoxSize;
802 switch (owner.View) {
804 // LAMESPEC: MSDN says, "In all views except the details
805 // view of the ListView, this value specifies the same
806 // bounding rectangle as the Entire value." Actually, it
807 // returns same bounding rectangles for Item and Entire
808 // values in the case of Details view.
810 // Handle reordered column
811 if (owner.Columns.Count > 0)
812 checkbox_rect.X = owner.Columns[0].Rect.X;
814 icon_rect = label_rect = Rectangle.Empty;
815 icon_rect.X = checkbox_rect.Right + 2;
816 item_ht = owner.ItemSize.Height;
818 if (owner.SmallImageList != null)
819 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
821 label_rect.Height = icon_rect.Height = item_ht;
822 checkbox_rect.Y = item_ht - checkbox_rect.Height;
824 label_rect.X = icon_rect.Right + 1;
826 if (owner.Columns.Count > 0)
827 label_rect.Width = owner.Columns[0].Wd - label_rect.X + checkbox_rect.X;
829 label_rect.Width = text_size.Width;
831 SizeF text_sz = TextRenderer.MeasureString (Text, Font);
832 text_bounds = label_rect;
833 text_bounds.Width = (int) text_sz.Width;
835 item_rect = total = Rectangle.Union
836 (Rectangle.Union (checkbox_rect, icon_rect), label_rect);
837 bounds.Size = total.Size;
841 for (int i = 0; i < owner.Columns.Count; i++) {
842 item_rect.Width += owner.Columns [i].Wd;
843 bounds.Width += owner.Columns [i].Wd;
846 // Bounds for sub items
847 int n = Math.Min (owner.Columns.Count, sub_items.Count);
848 for (int i = 0; i < n; i++) {
849 Rectangle col_rect = owner.Columns [i].Rect;
850 sub_items [i].SetBounds (col_rect.X, 0, col_rect.Width, item_ht);
855 label_rect = icon_rect = Rectangle.Empty;
857 SizeF sz = TextRenderer.MeasureString (Text, Font);
858 if ((int) sz.Width > text_size.Width) {
859 if (Focused && owner.InternalContainsFocus) {
860 int text_width = text_size.Width;
861 StringFormat format = new StringFormat ();
862 format.Alignment = StringAlignment.Center;
863 sz = TextRenderer.MeasureString (Text, Font, text_width, format);
864 text_size.Height = (int) sz.Height;
866 text_size.Height = 2 * (int) sz.Height;
869 if (owner.LargeImageList != null) {
870 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
871 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
874 if (checkbox_rect.Height > icon_rect.Height)
875 icon_rect.Y = checkbox_rect.Height - icon_rect.Height;
877 checkbox_rect.Y = icon_rect.Height - checkbox_rect.Height;
879 if (text_size.Width <= icon_rect.Width) {
880 icon_rect.X = checkbox_rect.Width + 1;
881 label_rect.X = icon_rect.X + (icon_rect.Width - text_size.Width) / 2;
882 label_rect.Y = icon_rect.Bottom + 2;
883 label_rect.Size = text_size;
885 int centerX = text_size.Width / 2;
886 icon_rect.X = checkbox_rect.Width + 1 + centerX - icon_rect.Width / 2;
887 label_rect.X = checkbox_rect.Width + 1;
888 label_rect.Y = icon_rect.Bottom + 2;
889 label_rect.Size = text_size;
892 item_rect = Rectangle.Union (icon_rect, label_rect);
893 total = Rectangle.Union (item_rect, checkbox_rect);
894 bounds.Size = total.Size;
899 label_rect = icon_rect = Rectangle.Empty;
900 icon_rect.X = checkbox_rect.Width + 1;
901 item_ht = Math.Max (owner.CheckBoxSize.Height, text_size.Height);
903 if (owner.SmallImageList != null) {
904 item_ht = Math.Max (item_ht, owner.SmallImageList.ImageSize.Height);
905 icon_rect.Width = owner.SmallImageList.ImageSize.Width;
906 icon_rect.Height = owner.SmallImageList.ImageSize.Height;
909 checkbox_rect.Y = item_ht - checkbox_rect.Height;
910 label_rect.X = icon_rect.Right + 1;
911 label_rect.Width = text_size.Width;
912 label_rect.Height = icon_rect.Height = item_ht;
914 item_rect = Rectangle.Union (icon_rect, label_rect);
915 total = Rectangle.Union (item_rect, checkbox_rect);
916 bounds.Size = total.Size;
920 label_rect = icon_rect = Rectangle.Empty;
922 if (owner.LargeImageList != null) {
923 icon_rect.Width = owner.LargeImageList.ImageSize.Width;
924 icon_rect.Height = owner.LargeImageList.ImageSize.Height;
928 SizeF tsize = TextRenderer.MeasureString (Text, Font);
930 // Set initial values for subitem's layout
931 int total_height = (int)Math.Ceiling (tsize.Height);
932 int max_subitem_width = (int)Math.Ceiling (tsize.Width);
933 SubItems [0].bounds.Height = total_height;
935 int count = Math.Min (owner.Columns.Count, SubItems.Count);
936 for (int i = 1; i < count; i++) { // Ignore first column and first subitem
937 ListViewSubItem sub_item = SubItems [i];
938 if (sub_item.Text == null || sub_item.Text.Length == 0)
941 tsize = TextRenderer.MeasureString (sub_item.Text, sub_item.Font);
943 int width = (int)Math.Ceiling (tsize.Width);
945 if (width > max_subitem_width)
946 max_subitem_width = width;
948 int height = (int)Math.Ceiling (tsize.Height);
949 total_height += height + separation;
951 sub_item.bounds.Height = height;
955 label_rect.X = icon_rect.Right + 4;
956 label_rect.Y = owner.TileSize.Height / 2 - total_height / 2;
957 label_rect.Width = max_subitem_width;
958 label_rect.Height = total_height;
960 // Second pass for assigning bounds. This time take first subitem into account.
961 int current_y = label_rect.Y;
962 for (int j = 0; j < count; j++) {
963 ListViewSubItem sub_item = SubItems [j];
964 if (sub_item.Text == null || sub_item.Text.Length == 0)
967 sub_item.SetBounds (label_rect.X, current_y, max_subitem_width, sub_item.bounds.Height);
968 current_y += sub_item.Bounds.Height + separation;
971 item_rect = Rectangle.Union (icon_rect, label_rect);
972 bounds.Size = item_rect.Size;
978 #endregion // Private Internal Methods
982 [DefaultProperty ("Text")]
983 [DesignTimeVisible (false)]
985 [ToolboxItem (false)]
986 [TypeConverter (typeof(ListViewSubItemConverter))]
987 public class ListViewSubItem
989 private Color back_color;
991 private Color fore_color;
992 internal ListViewItem owner;
993 private string text = string.Empty;
995 private string name = String.Empty;
998 internal Rectangle bounds;
1000 #region Public Constructors
1001 public ListViewSubItem ()
1005 public ListViewSubItem (ListViewItem owner, string text)
1006 : this (owner, text, Color.Empty,
1011 public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
1012 Color backColor, Font font)
1016 this.fore_color = foreColor;
1017 this.back_color = backColor;
1020 #endregion // Public Constructors
1022 #region Public Instance Properties
1023 public Color BackColor {
1025 if (this.back_color != Color.Empty)
1026 return this.back_color;
1027 if (this.owner != null && this.owner.ListView != null)
1028 return this.owner.ListView.BackColor;
1029 return ThemeEngine.Current.ColorWindow;
1045 Rectangle retval = bounds;
1046 if (owner != null) {
1047 retval.X += owner.Bounds.X;
1048 retval.Y += owner.Bounds.Y;
1055 [Localizable (true)]
1060 else if (owner != null)
1062 return ThemeEngine.Current.DefaultFont;
1072 public Color ForeColor {
1074 if (this.fore_color != Color.Empty)
1075 return this.fore_color;
1076 if (this.owner != null && this.owner.ListView != null)
1077 return this.owner.ListView.ForeColor;
1078 return ThemeEngine.Current.ColorWindowText;
1087 [Localizable (true)]
1088 public string Name {
1093 name = value == null ? String.Empty : value;
1097 [TypeConverter (typeof (StringConverter))]
1098 [BindableAttribute (true)]
1099 [DefaultValue (null)]
1100 [Localizable (false)]
1111 [Localizable (true)]
1112 public string Text {
1113 get { return text; }
1119 text = string.Empty;
1126 #endregion // Public Instance Properties
1128 #region Public Methods
1129 public void ResetStyle ()
1131 font = ThemeEngine.Current.DefaultFont;
1132 back_color = ThemeEngine.Current.DefaultControlBackColor;
1133 fore_color = ThemeEngine.Current.DefaultControlForeColor;
1137 public override string ToString ()
1139 return string.Format ("ListViewSubItem {{0}}", text);
1141 #endregion // Public Methods
1144 #region Private Methods
1145 private void Invalidate ()
1147 if (owner == null || owner.owner == null)
1150 owner.owner.Invalidate ();
1153 internal int Height {
1155 return bounds.Height;
1159 internal void SetBounds (int x, int y, int width, int height)
1161 bounds = new Rectangle (x, y, width, height);
1163 #endregion // Private Methods
1166 public class ListViewSubItemCollection : IList, ICollection, IEnumerable
1168 private ArrayList list;
1169 internal ListViewItem owner;
1171 #region Public Constructors
1172 public ListViewSubItemCollection (ListViewItem owner)
1175 this.list = new ArrayList ();
1177 #endregion // Public Constructors
1179 #region Public Properties
1182 get { return list.Count; }
1185 public bool IsReadOnly {
1186 get { return false; }
1189 public ListViewSubItem this [int index] {
1190 get { return (ListViewSubItem) list [index]; }
1192 value.owner = this.owner;
1193 list [index] = value;
1198 public virtual ListViewSubItem this [string key] {
1200 int idx = IndexOfKey (key);
1204 return (ListViewSubItem) list [idx];
1209 bool ICollection.IsSynchronized {
1210 get { return list.IsSynchronized; }
1213 object ICollection.SyncRoot {
1214 get { return list.SyncRoot; }
1217 bool IList.IsFixedSize {
1218 get { return list.IsFixedSize; }
1221 object IList.this [int index] {
1222 get { return this [index]; }
1224 if (! (value is ListViewSubItem))
1225 throw new ArgumentException ("Not of type ListViewSubItem", "value");
1226 this [index] = (ListViewSubItem) value;
1229 #endregion // Public Properties
1231 #region Public Methods
1232 public ListViewSubItem Add (ListViewSubItem item)
1234 item.owner = this.owner;
1239 public ListViewSubItem Add (string text)
1241 ListViewSubItem item = new ListViewSubItem (this.owner, text);
1246 public ListViewSubItem Add (string text, Color foreColor,
1247 Color backColor, Font font)
1249 ListViewSubItem item = new ListViewSubItem (this.owner, text,
1250 foreColor, backColor, font);
1255 public void AddRange (ListViewSubItem [] items)
1258 throw new ArgumentNullException ("items");
1260 foreach (ListViewSubItem item in items) {
1267 public void AddRange (string [] items)
1270 throw new ArgumentNullException ("items");
1272 foreach (string item in items) {
1279 public void AddRange (string [] items, Color foreColor,
1280 Color backColor, Font font)
1283 throw new ArgumentNullException ("items");
1285 foreach (string item in items) {
1288 this.Add (item, foreColor, backColor, font);
1292 public void Clear ()
1297 public bool Contains (ListViewSubItem item)
1299 return list.Contains (item);
1303 public virtual bool ContainsKey (string key)
1305 return IndexOfKey (key) != -1;
1309 public IEnumerator GetEnumerator ()
1311 return list.GetEnumerator ();
1314 void ICollection.CopyTo (Array dest, int index)
1316 list.CopyTo (dest, index);
1319 int IList.Add (object item)
1321 if (! (item is ListViewSubItem)) {
1322 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1325 ListViewSubItem sub_item = (ListViewSubItem) item;
1326 sub_item.owner = this.owner;
1327 return list.Add (sub_item);
1330 bool IList.Contains (object subItem)
1332 if (! (subItem is ListViewSubItem)) {
1333 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1336 return this.Contains ((ListViewSubItem) subItem);
1339 int IList.IndexOf (object subItem)
1341 if (! (subItem is ListViewSubItem)) {
1342 throw new ArgumentException ("Not of type ListViewSubItem", "subItem");
1345 return this.IndexOf ((ListViewSubItem) subItem);
1348 void IList.Insert (int index, object item)
1350 if (! (item is ListViewSubItem)) {
1351 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1354 this.Insert (index, (ListViewSubItem) item);
1357 void IList.Remove (object item)
1359 if (! (item is ListViewSubItem)) {
1360 throw new ArgumentException ("Not of type ListViewSubItem", "item");
1363 this.Remove ((ListViewSubItem) item);
1366 public int IndexOf (ListViewSubItem subItem)
1368 return list.IndexOf (subItem);
1372 public virtual int IndexOfKey (string key)
1374 if (key == null || key.Length == 0)
1377 for (int i = 0; i < list.Count; i++) {
1378 ListViewSubItem l = (ListViewSubItem) list [i];
1379 if (String.Compare (l.Name, key, true) == 0)
1387 public void Insert (int index, ListViewSubItem item)
1389 item.owner = this.owner;
1390 list.Insert (index, item);
1393 public void Remove (ListViewSubItem item)
1399 public virtual void RemoveByKey (string key)
1401 int idx = IndexOfKey (key);
1407 public void RemoveAt (int index)
1409 list.RemoveAt (index);
1411 #endregion // Public Methods
1413 #endregion // Subclasses