ListViewItem.cs 20 KB

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