ListViewItem.cs 20 KB

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