ListView.cs 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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.2 $
  26. // $Modtime: $
  27. // $Log: ListView.cs,v $
  28. // Revision 1.2 2004/10/02 11:32:01 ravindra
  29. // Added attributes.
  30. //
  31. // Revision 1.1 2004/09/30 13:24:25 ravindra
  32. // Initial implementation.
  33. //
  34. //
  35. // NOT COMPLETE
  36. //
  37. using System.Collections;
  38. using System.ComponentModel;
  39. using System.ComponentModel.Design;
  40. using System.Drawing;
  41. using System.Runtime.InteropServices;
  42. namespace System.Windows.Forms
  43. {
  44. [DefaultEvent ("SelectedIndexChanged")]
  45. [DefaultProperty ("Items")]
  46. [Designer ("System.Windows.Forms.Design.ListViewDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  47. public class ListView : Control
  48. {
  49. private ItemActivation activation = ItemActivation.Standard;
  50. private ListViewAlignment alignment = ListViewAlignment.Top;
  51. private bool allowColumnReorder = false;
  52. private bool autoArrange = true;
  53. private BorderStyle borderStyle = BorderStyle.Fixed3D;
  54. private bool checkBoxes = false;
  55. private CheckedIndexCollection checkedIndices;
  56. private CheckedListViewItemCollection checkedItems;
  57. private ColumnHeaderCollection columns;
  58. private ListViewItem focusedItem;
  59. private bool fullRowSelect = false;
  60. private bool gridLines = false;
  61. private ColumnHeaderStyle headerStyle = ColumnHeaderStyle.Clickable;
  62. private bool hideSelection = true;
  63. private bool hoverSelection = false;
  64. private ListViewItemCollection items;
  65. private bool labelEdit = false;
  66. private bool labelWrap = true;
  67. internal ImageList largeImageList;
  68. private IComparer itemSorter;
  69. private bool multiselect = true;
  70. private bool redraw = true;
  71. private bool scrollable = true;
  72. private SelectedIndexCollection selectedIndices;
  73. private SelectedListViewItemCollection selectedItems;
  74. internal ImageList smallImageList;
  75. private SortOrder sortOrder = SortOrder.None;
  76. private ImageList stateImageList;
  77. private bool updating = false;
  78. private View view = View.LargeIcon;
  79. #region Events
  80. public event LabelEditEventHandler AfterLabelEdit;
  81. [Browsable (false)]
  82. [EditorBrowsable (EditorBrowsableState.Never)]
  83. public new event EventHandler BackgroundImageChanged;
  84. public event LabelEditEventHandler BeforeLabelEdit;
  85. public event ColumnClickEventHandler ColumnClick;
  86. public event EventHandler ItemActivate;
  87. public event ItemCheckEventHandler ItemCheck;
  88. public event ItemDragEventHandler ItemDrag;
  89. [Browsable (false)]
  90. [EditorBrowsable (EditorBrowsableState.Never)]
  91. public new event PaintEventHandler Paint;
  92. public event EventHandler SelectedIndexChanged;
  93. [Browsable (false)]
  94. [EditorBrowsable (EditorBrowsableState.Never)]
  95. public new event EventHandler TextChanged;
  96. #endregion // Events
  97. #region Public Constructors
  98. public ListView ()
  99. {
  100. checkedIndices = new CheckedIndexCollection (this);
  101. checkedItems = new CheckedListViewItemCollection (this);
  102. columns = new ColumnHeaderCollection (this);
  103. items = new ListViewItemCollection (this);
  104. selectedIndices = new SelectedIndexCollection (this);
  105. selectedItems = new SelectedListViewItemCollection (this);
  106. }
  107. #endregion // Public Constructors
  108. #region Protected Properties
  109. protected override CreateParams CreateParams {
  110. get { return base.CreateParams; }
  111. }
  112. protected override Size DefaultSize {
  113. get { return new Size (121, 97); }
  114. }
  115. #endregion // Protected Properties
  116. #region Public Instance Properties
  117. [DefaultValue (ItemActivation.Standard)]
  118. public ItemActivation Activation {
  119. get { return activation; }
  120. set { activation = value; }
  121. }
  122. [DefaultValue (ListViewAlignment.Top)]
  123. [Localizable (true)]
  124. public ListViewAlignment Alignment {
  125. get { return alignment; }
  126. set { alignment = value; }
  127. }
  128. [DefaultValue (false)]
  129. public bool AllowColumnReorder {
  130. get { return allowColumnReorder; }
  131. set { allowColumnReorder = value; }
  132. }
  133. [DefaultValue (true)]
  134. public bool AutoArrange {
  135. get { return autoArrange; }
  136. set { autoArrange = value; }
  137. }
  138. public override Color BackColor {
  139. get { return base.BackColor; }
  140. set { base.BackColor = value; }
  141. }
  142. [Browsable (false)]
  143. [EditorBrowsable (EditorBrowsableState.Never)]
  144. public override Image BackgroundImage {
  145. get { return background_image; }
  146. set {
  147. if (value == background_image)
  148. return;
  149. background_image = value;
  150. if (BackgroundImageChanged != null)
  151. BackgroundImageChanged (this, new EventArgs ());
  152. }
  153. }
  154. [DefaultValue (BorderStyle.Fixed3D)]
  155. [DispId (-504)]
  156. public BorderStyle BorderStyle {
  157. get { return borderStyle; }
  158. set { borderStyle = value; }
  159. }
  160. [DefaultValue (false)]
  161. public bool CheckBoxes {
  162. get { return checkBoxes; }
  163. set { checkBoxes = value; }
  164. }
  165. [Browsable (false)]
  166. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  167. public CheckedIndexCollection CheckedIndices {
  168. get { return checkedIndices; }
  169. }
  170. [Browsable (false)]
  171. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  172. public CheckedListViewItemCollection CheckedItems {
  173. get { return checkedItems; }
  174. }
  175. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  176. [Localizable (true)]
  177. [MergableProperty (false)]
  178. public ColumnHeaderCollection Columns {
  179. get { return columns; }
  180. }
  181. [Browsable (false)]
  182. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  183. public ListViewItem FocusedItem {
  184. get { return focusedItem; }
  185. }
  186. public override Color ForeColor {
  187. get { return base.ForeColor; }
  188. set { base.ForeColor = value; }
  189. }
  190. [DefaultValue (false)]
  191. public bool FullRowSelect {
  192. get { return fullRowSelect; }
  193. set { fullRowSelect = value; }
  194. }
  195. [DefaultValue (false)]
  196. public bool GridLines {
  197. get { return gridLines; }
  198. set { gridLines = value; }
  199. }
  200. [DefaultValue (ColumnHeaderStyle.Clickable)]
  201. public ColumnHeaderStyle HeaderStyle {
  202. get { return headerStyle; }
  203. set { headerStyle = value; }
  204. }
  205. [DefaultValue (true)]
  206. public bool HideSelection {
  207. get { return hideSelection; }
  208. set { hideSelection = value; }
  209. }
  210. [DefaultValue (false)]
  211. public bool HoverSelection {
  212. get { return hoverSelection; }
  213. set { hoverSelection = value; }
  214. }
  215. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  216. [Localizable (true)]
  217. [MergableProperty (false)]
  218. public ListViewItemCollection Items {
  219. get { return items; }
  220. }
  221. [DefaultValue (false)]
  222. public bool LabelEdit {
  223. get { return labelEdit; }
  224. set { labelEdit = value; }
  225. }
  226. [DefaultValue (false)]
  227. [Localizable (true)]
  228. public bool LabelWrap {
  229. get { return labelWrap; }
  230. set { labelWrap = value; }
  231. }
  232. [DefaultValue (null)]
  233. public ImageList LargeImageList {
  234. get { return largeImageList; }
  235. set { largeImageList = value; }
  236. }
  237. [Browsable (false)]
  238. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  239. public IComparer ListViewItemSorter {
  240. get { return itemSorter; }
  241. set { itemSorter = value; }
  242. }
  243. [DefaultValue (true)]
  244. public bool MultiSelect {
  245. get { return multiselect; }
  246. set { multiselect = value; }
  247. }
  248. [DefaultValue (true)]
  249. public bool Scrollable {
  250. get { return scrollable; }
  251. set { scrollable = value; }
  252. }
  253. [Browsable (false)]
  254. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  255. public SelectedIndexCollection SelectedIndices {
  256. get { return selectedIndices; }
  257. }
  258. [Browsable (false)]
  259. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  260. public SelectedListViewItemCollection SelectedItems {
  261. get { return selectedItems; }
  262. }
  263. [DefaultValue (null)]
  264. public ImageList SmallImageList {
  265. get { return smallImageList; }
  266. set { smallImageList = value; }
  267. }
  268. [DefaultValue (SortOrder.None)]
  269. public SortOrder Sorting {
  270. get { return sortOrder; }
  271. set { sortOrder = value; }
  272. }
  273. [DefaultValue (null)]
  274. public ImageList StateImageList {
  275. get { return stateImageList; }
  276. set { stateImageList = value; }
  277. }
  278. [Bindable (false)]
  279. [Browsable (false)]
  280. [EditorBrowsable (EditorBrowsableState.Never)]
  281. public override string Text {
  282. get { return text; }
  283. set {
  284. if (value == text)
  285. return;
  286. text = value;
  287. if (TextChanged != null)
  288. TextChanged (this, new EventArgs ());
  289. }
  290. }
  291. [Browsable (false)]
  292. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  293. public ListViewItem TopItem {
  294. get { return items [0]; }
  295. }
  296. [DefaultValue (View.LargeIcon)]
  297. public View View {
  298. get { return view; }
  299. set { view = value; }
  300. }
  301. #endregion // Public Instance Properties
  302. #region Internal Methods
  303. internal void Redraw (bool recalculate)
  304. {
  305. if (recalculate)
  306. CalculateListView ();
  307. redraw = true;
  308. }
  309. private void CalculateListView ()
  310. {
  311. // FIXME: TODO
  312. }
  313. #endregion // Internal Methods
  314. #region Protected Methods
  315. protected override void CreateHandle ()
  316. {
  317. base.CreateHandle ();
  318. }
  319. protected override void Dispose (bool disposing)
  320. {
  321. Clear ();
  322. }
  323. protected override bool IsInputKey (Keys keyData)
  324. {
  325. return base.IsInputKey (keyData);
  326. }
  327. protected virtual void OnAfterLabelEdit (LabelEditEventArgs e)
  328. {
  329. if (AfterLabelEdit != null)
  330. AfterLabelEdit (this, e);
  331. }
  332. protected virtual void OnBeforeLabelEdit (LabelEditEventArgs e)
  333. {
  334. if (BeforeLabelEdit != null)
  335. BeforeLabelEdit (this, e);
  336. }
  337. protected virtual void OnColumnClick (ColumnClickEventArgs e)
  338. {
  339. if (ColumnClick != null)
  340. ColumnClick (this, e);
  341. }
  342. protected override void OnEnabledChanged (EventArgs e)
  343. {
  344. base.OnEnabledChanged (e);
  345. }
  346. protected override void OnFontChanged (EventArgs e)
  347. {
  348. base.OnFontChanged (e);
  349. }
  350. protected override void OnHandleCreated (EventArgs e)
  351. {
  352. base.OnHandleCreated (e);
  353. }
  354. protected override void OnHandleDestroyed (EventArgs e)
  355. {
  356. base.OnHandleDestroyed (e);
  357. }
  358. protected virtual void OnItemActivate (EventArgs e)
  359. {
  360. if (ItemActivate != null)
  361. ItemActivate (this, e);
  362. }
  363. protected virtual void OnItemCheck (ItemCheckEventArgs ice)
  364. {
  365. if (ItemCheck != null)
  366. ItemCheck (this, ice);
  367. }
  368. protected virtual void OnItemDrag (ItemDragEventArgs e)
  369. {
  370. if (ItemDrag != null)
  371. ItemDrag (this, e);
  372. }
  373. protected virtual void OnSelectedIndexChanged (EventArgs e)
  374. {
  375. if (SelectedIndexChanged != null)
  376. SelectedIndexChanged (this, e);
  377. }
  378. protected override void OnSystemColorsChanged (EventArgs e)
  379. {
  380. base.OnSystemColorsChanged (e);
  381. }
  382. protected void RealizeProperties ()
  383. {
  384. // FIXME: TODO
  385. }
  386. protected void UpdateExtendedStyles ()
  387. {
  388. // FIXME: TODO
  389. }
  390. protected override void WndProc (ref Message m)
  391. {
  392. base.WndProc (ref m);
  393. }
  394. #endregion // Protected Methods
  395. #region Public Instance Methods
  396. public void ArrangeIcons ()
  397. {
  398. ArrangeIcons (ListViewAlignment.Default);
  399. }
  400. public void ArrangeIcons (ListViewAlignment alignment)
  401. {
  402. // Icons are arranged only if view is set to LargeIcon or SmallIcon
  403. if (view == View.LargeIcon || view == View.SmallIcon) {
  404. // FIXME: TODO
  405. }
  406. }
  407. public void BeginUpdate ()
  408. {
  409. // flag to avoid painting
  410. updating = true;
  411. }
  412. public void Clear ()
  413. {
  414. columns.Clear ();
  415. items.Clear ();
  416. }
  417. public void EndUpdate ()
  418. {
  419. // flag to avoid painting
  420. updating = false;
  421. }
  422. public void EnsureVisible (int index)
  423. {
  424. // FIXME: TODO
  425. }
  426. public ListViewItem GetItemAt (int x, int y)
  427. {
  428. foreach (ListViewItem item in items) {
  429. if (item.Bounds.Contains (x, y))
  430. return item;
  431. }
  432. return null;
  433. }
  434. public Rectangle GetItemRect (int index)
  435. {
  436. return GetItemRect (index, ItemBoundsPortion.Entire);
  437. }
  438. public Rectangle GetItemRect (int index, ItemBoundsPortion portion)
  439. {
  440. if (index < 0 || index >= items.Count)
  441. throw new IndexOutOfRangeException ("Invalid Index");
  442. return items [index].GetBounds (portion);
  443. }
  444. public void Sort ()
  445. {
  446. if (sortOrder != SortOrder.None)
  447. items.list.Sort (itemSorter);
  448. if (sortOrder == SortOrder.Descending)
  449. items.list.Reverse ();
  450. }
  451. public override string ToString ()
  452. {
  453. int count = this.Items.Count;
  454. if (count == 0)
  455. return string.Format ("System.Windows.Forms.ListView, Items.Count: 0");
  456. else
  457. return string.Format ("System.Windows.Forms.ListView, Items.Count: {0}, Items[0]: {1}", count, this.Items [0].ToString ());
  458. }
  459. #endregion // Public Instance Methods
  460. #region Subclasses
  461. public class CheckedIndexCollection : IList, ICollection, IEnumerable
  462. {
  463. internal ArrayList list;
  464. private ListView owner;
  465. #region Public Constructor
  466. public CheckedIndexCollection (ListView owner)
  467. {
  468. list = new ArrayList ();
  469. this.owner = owner;
  470. }
  471. #endregion // Public Constructor
  472. #region Public Properties
  473. [Browsable (false)]
  474. public virtual int Count {
  475. get { return list.Count; }
  476. }
  477. public virtual bool IsReadOnly {
  478. get { return true; }
  479. }
  480. public int this [int index] {
  481. get {
  482. if (index < 0 || index >= list.Count)
  483. throw new ArgumentOutOfRangeException ("Index out of range.");
  484. return (int) list [index];
  485. }
  486. }
  487. bool ICollection.IsSynchronized {
  488. get { return list.IsSynchronized; }
  489. }
  490. object ICollection.SyncRoot {
  491. get { return list.SyncRoot; }
  492. }
  493. bool IList.IsFixedSize {
  494. get { return list.IsFixedSize; }
  495. }
  496. object IList.this [int index] {
  497. get { return this [index]; }
  498. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  499. }
  500. #endregion // Public Properties
  501. #region Public Methods
  502. public bool Contains (int checkedIndex)
  503. {
  504. return list.Contains (checkedIndex);
  505. }
  506. public virtual IEnumerator GetEnumerator ()
  507. {
  508. return list.GetEnumerator ();
  509. }
  510. void ICollection.CopyTo (Array dest, int index)
  511. {
  512. list.CopyTo (dest, index);
  513. }
  514. int IList.Add (object value)
  515. {
  516. throw new NotSupportedException ("Add operation is not supported.");
  517. }
  518. void IList.Clear ()
  519. {
  520. throw new NotSupportedException ("Clear operation is not supported.");
  521. }
  522. bool IList.Contains (object checkedIndex)
  523. {
  524. return list.Contains (checkedIndex);
  525. }
  526. int IList.IndexOf (object checkedIndex)
  527. {
  528. return list.IndexOf (checkedIndex);
  529. }
  530. void IList.Insert (int index, object value)
  531. {
  532. throw new NotSupportedException ("Insert operation is not supported.");
  533. }
  534. void IList.Remove (object value)
  535. {
  536. throw new NotSupportedException ("Remove operation is not supported.");
  537. }
  538. void IList.RemoveAt (int index)
  539. {
  540. throw new NotSupportedException ("RemoveAt operation is not supported.");
  541. }
  542. public int IndexOf (int checkedIndex)
  543. {
  544. return list.IndexOf (checkedIndex);
  545. }
  546. #endregion // Public Methods
  547. } // CheckedIndexCollection
  548. public class CheckedListViewItemCollection : IList, ICollection, IEnumerable
  549. {
  550. internal ArrayList list;
  551. private ListView owner;
  552. #region Public Constructor
  553. public CheckedListViewItemCollection (ListView owner)
  554. {
  555. list = new ArrayList ();
  556. this.owner = owner;
  557. }
  558. #endregion // Public Constructor
  559. #region Public Properties
  560. [Browsable (false)]
  561. public virtual int Count {
  562. get { return list.Count; }
  563. }
  564. public virtual bool IsReadOnly {
  565. get { return true; }
  566. }
  567. public ListViewItem this [int index] {
  568. get {
  569. if (index < 0 || index >= list.Count)
  570. throw new ArgumentOutOfRangeException ("Index out of range.");
  571. return (ListViewItem) list [index];
  572. }
  573. }
  574. bool ICollection.IsSynchronized {
  575. get { return list.IsSynchronized; }
  576. }
  577. object ICollection.SyncRoot {
  578. get { return list.SyncRoot; }
  579. }
  580. bool IList.IsFixedSize {
  581. get { return list.IsFixedSize; }
  582. }
  583. object IList.this [int index] {
  584. get { return this [index]; }
  585. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  586. }
  587. #endregion // Public Properties
  588. #region Public Methods
  589. public bool Contains (ListViewItem item)
  590. {
  591. return list.Contains (item);
  592. }
  593. public virtual void CopyTo (Array dest, int index)
  594. {
  595. list.CopyTo (dest, index);
  596. }
  597. public virtual IEnumerator GetEnumerator ()
  598. {
  599. return list.GetEnumerator ();
  600. }
  601. int IList.Add (object value)
  602. {
  603. throw new NotSupportedException ("Add operation is not supported.");
  604. }
  605. void IList.Clear ()
  606. {
  607. throw new NotSupportedException ("Clear operation is not supported.");
  608. }
  609. bool IList.Contains (object item)
  610. {
  611. return list.Contains (item);
  612. }
  613. int IList.IndexOf (object item)
  614. {
  615. return list.IndexOf (item);
  616. }
  617. void IList.Insert (int index, object value)
  618. {
  619. throw new NotSupportedException ("Insert operation is not supported.");
  620. }
  621. void IList.Remove (object value)
  622. {
  623. throw new NotSupportedException ("Remove operation is not supported.");
  624. }
  625. void IList.RemoveAt (int index)
  626. {
  627. throw new NotSupportedException ("RemoveAt operation is not supported.");
  628. }
  629. public int IndexOf (ListViewItem item)
  630. {
  631. return list.IndexOf (item);
  632. }
  633. #endregion // Public Methods
  634. } // CheckedListViewItemCollection
  635. public class ColumnHeaderCollection : IList, ICollection, IEnumerable
  636. {
  637. internal ArrayList list;
  638. private ListView owner;
  639. #region Public Constructor
  640. public ColumnHeaderCollection (ListView owner)
  641. {
  642. list = new ArrayList ();
  643. this.owner = owner;
  644. }
  645. #endregion // Public Constructor
  646. #region Public Properties
  647. [Browsable (false)]
  648. public virtual int Count {
  649. get { return list.Count; }
  650. }
  651. public virtual bool IsReadOnly {
  652. get { return false; }
  653. }
  654. public virtual ColumnHeader this [int index] {
  655. get {
  656. if (index < 0 || index >= list.Count)
  657. throw new ArgumentOutOfRangeException ("Index out of range.");
  658. return (ColumnHeader) list [index];
  659. }
  660. }
  661. bool ICollection.IsSynchronized {
  662. get { return list.IsSynchronized; }
  663. }
  664. object ICollection.SyncRoot {
  665. get { return list.SyncRoot; }
  666. }
  667. bool IList.IsFixedSize {
  668. get { return list.IsFixedSize; }
  669. }
  670. object IList.this [int index] {
  671. get { return this [index]; }
  672. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  673. }
  674. #endregion // Public Properties
  675. #region Public Methods
  676. public virtual int Add (ColumnHeader value)
  677. {
  678. return list.Add (value);
  679. }
  680. public virtual ColumnHeader Add (string str, int width, HorizontalAlignment textAlign)
  681. {
  682. ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
  683. this.Add (colHeader);
  684. return colHeader;
  685. }
  686. public virtual void AddRange (ColumnHeader [] values)
  687. {
  688. foreach (ColumnHeader colHeader in values)
  689. this.Add (colHeader);
  690. }
  691. public virtual void Clear ()
  692. {
  693. list.Clear ();
  694. }
  695. public bool Contains (ColumnHeader value)
  696. {
  697. return list.Contains (value);
  698. }
  699. public virtual IEnumerator GetEnumerator ()
  700. {
  701. return list.GetEnumerator ();
  702. }
  703. void ICollection.CopyTo (Array dest, int index)
  704. {
  705. list.CopyTo (dest, index);
  706. }
  707. int IList.Add (object value)
  708. {
  709. if (! (value is ColumnHeader)) {
  710. throw new ArgumentException("Not of type ColumnHeader", "value");
  711. }
  712. return this.Add ((ColumnHeader) value);
  713. }
  714. bool IList.Contains (object value)
  715. {
  716. if (! (value is ColumnHeader)) {
  717. throw new ArgumentException("Not of type ColumnHeader", "value");
  718. }
  719. return this.Contains ((ColumnHeader) value);
  720. }
  721. int IList.IndexOf (object value)
  722. {
  723. if (! (value is ColumnHeader)) {
  724. throw new ArgumentException("Not of type ColumnHeader", "value");
  725. }
  726. return this.IndexOf ((ColumnHeader) value);
  727. }
  728. void IList.Insert (int index, object value)
  729. {
  730. if (! (value is ColumnHeader)) {
  731. throw new ArgumentException("Not of type ColumnHeader", "value");
  732. }
  733. this.Insert (index, (ColumnHeader) value);
  734. }
  735. void IList.Remove (object value)
  736. {
  737. if (! (value is ColumnHeader)) {
  738. throw new ArgumentException("Not of type ColumnHeader", "value");
  739. }
  740. this.Remove ((ColumnHeader) value);
  741. }
  742. public int IndexOf (ColumnHeader value)
  743. {
  744. return list.IndexOf (value);
  745. }
  746. public void Insert (int index, ColumnHeader value)
  747. {
  748. if (index < 0 || index >= list.Count)
  749. throw new ArgumentOutOfRangeException ("Index out of range.");
  750. list.Insert (index, value);
  751. }
  752. public void Insert (int index, string str, int width, HorizontalAlignment textAlign)
  753. {
  754. ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
  755. this.Insert (index, colHeader);
  756. }
  757. public virtual void Remove (ColumnHeader column)
  758. {
  759. list.Remove (column);
  760. }
  761. public virtual void RemoveAt (int index)
  762. {
  763. if (index < 0 || index >= list.Count)
  764. throw new ArgumentOutOfRangeException ("Index out of range.");
  765. list.RemoveAt (index);
  766. }
  767. #endregion // Public Methods
  768. } // ColumnHeaderCollection
  769. public class ListViewItemCollection : IList, ICollection, IEnumerable
  770. {
  771. internal ArrayList list;
  772. private ListView owner;
  773. #region Public Constructor
  774. public ListViewItemCollection (ListView owner)
  775. {
  776. list = new ArrayList ();
  777. this.owner = owner;
  778. }
  779. #endregion // Public Constructor
  780. #region Public Properties
  781. [Browsable (false)]
  782. public virtual int Count {
  783. get { return list.Count; }
  784. }
  785. public virtual bool IsReadOnly {
  786. get { return false; }
  787. }
  788. public virtual ListViewItem this [int displayIndex] {
  789. get {
  790. if (displayIndex < 0 || displayIndex >= list.Count)
  791. throw new ArgumentOutOfRangeException ("Index out of range.");
  792. return (ListViewItem) list [displayIndex];
  793. }
  794. set {
  795. if (displayIndex < 0 || displayIndex >= list.Count)
  796. throw new ArgumentOutOfRangeException ("Index out of range.");
  797. value.owner = this.owner;
  798. list [displayIndex] = value;
  799. owner.Redraw (true);
  800. }
  801. }
  802. bool ICollection.IsSynchronized {
  803. get { return list.IsSynchronized; }
  804. }
  805. object ICollection.SyncRoot {
  806. get { return list.SyncRoot; }
  807. }
  808. bool IList.IsFixedSize {
  809. get { return list.IsFixedSize; }
  810. }
  811. object IList.this [int index] {
  812. get { return this [index]; }
  813. set {
  814. if (value is ListViewItem)
  815. this [index] = (ListViewItem) value;
  816. else
  817. this [index] = new ListViewItem (value.ToString ());
  818. }
  819. }
  820. #endregion // Public Properties
  821. #region Public Methods
  822. public virtual ListViewItem Add (ListViewItem value)
  823. {
  824. value.owner = this.owner;
  825. list.Add (value);
  826. if (owner.Sorting != SortOrder.None)
  827. owner.Sort ();
  828. owner.Redraw (true);
  829. return value;
  830. }
  831. public virtual ListViewItem Add (string text)
  832. {
  833. ListViewItem item = new ListViewItem (text);
  834. return this.Add (item);
  835. }
  836. public virtual ListViewItem Add (string text, int imageIndex)
  837. {
  838. ListViewItem item = new ListViewItem (text, imageIndex);
  839. return this.Add (item);
  840. }
  841. public void AddRange (ListViewItem [] values)
  842. {
  843. list.Clear ();
  844. foreach (ListViewItem item in values) {
  845. item.owner = this.owner;
  846. list.Add (item);
  847. }
  848. if (owner.Sorting != SortOrder.None)
  849. owner.Sort ();
  850. owner.Redraw (true);
  851. }
  852. public virtual void Clear ()
  853. {
  854. list.Clear ();
  855. owner.Redraw (true);
  856. }
  857. public bool Contains (ListViewItem item)
  858. {
  859. return list.Contains (item);
  860. }
  861. public virtual void CopyTo (Array dest, int index)
  862. {
  863. list.CopyTo (dest, index);
  864. }
  865. public virtual IEnumerator GetEnumerator ()
  866. {
  867. return list.GetEnumerator ();
  868. }
  869. int IList.Add (object item)
  870. {
  871. int result;
  872. ListViewItem li;
  873. if (item is ListViewItem)
  874. li = (ListViewItem) item;
  875. else
  876. li = new ListViewItem (item.ToString ());
  877. li.owner = this.owner;
  878. result = list.Add (li);
  879. owner.Redraw (true);
  880. return result;
  881. }
  882. bool IList.Contains (object item)
  883. {
  884. return list.Contains (item);
  885. }
  886. int IList.IndexOf (object item)
  887. {
  888. return list.IndexOf (item);
  889. }
  890. void IList.Insert (int index, object item)
  891. {
  892. if (item is ListViewItem)
  893. this.Insert (index, (ListViewItem) item);
  894. else
  895. this.Insert (index, item.ToString ());
  896. }
  897. void IList.Remove (object item)
  898. {
  899. if (list.Contains (item)) {
  900. list.Remove (item);
  901. owner.Redraw (true);
  902. }
  903. }
  904. public int IndexOf (ListViewItem item)
  905. {
  906. return list.IndexOf (item);
  907. }
  908. public ListViewItem Insert (int index, ListViewItem item)
  909. {
  910. if (index < 0 || index >= list.Count)
  911. throw new ArgumentOutOfRangeException ("Index out of range.");
  912. item.owner = this.owner;
  913. list.Insert (index, item);
  914. owner.Redraw (true);
  915. return item;
  916. }
  917. public ListViewItem Insert (int index, string text)
  918. {
  919. return this.Insert (index, new ListViewItem (text));
  920. }
  921. public ListViewItem Insert (int index, string text, int imageIndex)
  922. {
  923. return this.Insert (index, new ListViewItem (text, imageIndex));
  924. }
  925. public virtual void Remove (ListViewItem item)
  926. {
  927. if (list.Contains (item)) {
  928. list.Remove (item);
  929. owner.Redraw (true);
  930. }
  931. }
  932. public virtual void RemoveAt (int index)
  933. {
  934. if (index < 0 || index >= list.Count)
  935. throw new ArgumentOutOfRangeException ("Index out of range.");
  936. list.RemoveAt (index);
  937. owner.Redraw (false);
  938. }
  939. #endregion // Public Methods
  940. } // ListViewItemCollection
  941. public class SelectedIndexCollection : IList, ICollection, IEnumerable
  942. {
  943. internal ArrayList list;
  944. private ListView owner;
  945. #region Public Constructor
  946. public SelectedIndexCollection (ListView owner)
  947. {
  948. list = new ArrayList ();
  949. this.owner = owner;
  950. }
  951. #endregion // Public Constructor
  952. #region Public Properties
  953. [Browsable (false)]
  954. public virtual int Count {
  955. get { return list.Count; }
  956. }
  957. public virtual bool IsReadOnly {
  958. get { return true; }
  959. }
  960. public int this [int index] {
  961. get {
  962. if (index < 0 || index >= list.Count)
  963. throw new ArgumentOutOfRangeException ("Index out of range.");
  964. return (int) list [index];
  965. }
  966. }
  967. bool ICollection.IsSynchronized {
  968. get { return list.IsSynchronized; }
  969. }
  970. object ICollection.SyncRoot {
  971. get { return list.SyncRoot; }
  972. }
  973. bool IList.IsFixedSize {
  974. get { return list.IsFixedSize; }
  975. }
  976. object IList.this [int index] {
  977. get { return this [index]; }
  978. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  979. }
  980. #endregion // Public Properties
  981. #region Public Methods
  982. public bool Contains (int selectedIndex)
  983. {
  984. return list.Contains (selectedIndex);
  985. }
  986. public virtual void CopyTo (Array dest, int index)
  987. {
  988. list.CopyTo (dest, index);
  989. }
  990. public virtual IEnumerator GetEnumerator ()
  991. {
  992. return list.GetEnumerator ();
  993. }
  994. int IList.Add (object value)
  995. {
  996. throw new NotSupportedException ("Add operation is not supported.");
  997. }
  998. void IList.Clear ()
  999. {
  1000. throw new NotSupportedException ("Clear operation is not supported.");
  1001. }
  1002. bool IList.Contains (object selectedIndex)
  1003. {
  1004. return list.Contains (selectedIndex);
  1005. }
  1006. int IList.IndexOf (object selectedIndex)
  1007. {
  1008. return list.IndexOf (selectedIndex);
  1009. }
  1010. void IList.Insert (int index, object value)
  1011. {
  1012. throw new NotSupportedException ("Insert operation is not supported.");
  1013. }
  1014. void IList.Remove (object value)
  1015. {
  1016. throw new NotSupportedException ("Remove operation is not supported.");
  1017. }
  1018. void IList.RemoveAt (int index)
  1019. {
  1020. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1021. }
  1022. public int IndexOf (int selectedIndex)
  1023. {
  1024. return list.IndexOf (selectedIndex);
  1025. }
  1026. #endregion // Public Methods
  1027. } // SelectedIndexCollection
  1028. public class SelectedListViewItemCollection : IList, ICollection, IEnumerable
  1029. {
  1030. internal ArrayList list;
  1031. private ListView owner;
  1032. #region Public Constructor
  1033. public SelectedListViewItemCollection (ListView owner)
  1034. {
  1035. list = new ArrayList ();
  1036. this.owner = owner;
  1037. }
  1038. #endregion // Public Constructor
  1039. #region Public Properties
  1040. [Browsable (false)]
  1041. public virtual int Count {
  1042. get { return list.Count; }
  1043. }
  1044. public virtual bool IsReadOnly {
  1045. get { return true; }
  1046. }
  1047. public ListViewItem this [int index] {
  1048. get {
  1049. if (index < 0 || index >= list.Count)
  1050. throw new ArgumentOutOfRangeException ("Index out of range.");
  1051. return (ListViewItem) list [index];
  1052. }
  1053. }
  1054. bool ICollection.IsSynchronized {
  1055. get { return list.IsSynchronized; }
  1056. }
  1057. object ICollection.SyncRoot {
  1058. get { return list.SyncRoot; }
  1059. }
  1060. bool IList.IsFixedSize {
  1061. get { return list.IsFixedSize; }
  1062. }
  1063. object IList.this [int index] {
  1064. get { return this [index]; }
  1065. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1066. }
  1067. #endregion // Public Properties
  1068. #region Public Methods
  1069. public virtual void Clear ()
  1070. {
  1071. list.Clear ();
  1072. }
  1073. public bool Contains (ListViewItem item)
  1074. {
  1075. return list.Contains (item);
  1076. }
  1077. public virtual void CopyTo (Array dest, int index)
  1078. {
  1079. list.CopyTo (dest, index);
  1080. }
  1081. public virtual IEnumerator GetEnumerator ()
  1082. {
  1083. return list.GetEnumerator ();
  1084. }
  1085. int IList.Add (object value)
  1086. {
  1087. throw new NotSupportedException ("Add operation is not supported.");
  1088. }
  1089. bool IList.Contains (object item)
  1090. {
  1091. return list.Contains (item);
  1092. }
  1093. int IList.IndexOf (object item)
  1094. {
  1095. return list.IndexOf (item);
  1096. }
  1097. void IList.Insert (int index, object value)
  1098. {
  1099. throw new NotSupportedException ("Insert operation is not supported.");
  1100. }
  1101. void IList.Remove (object value)
  1102. {
  1103. throw new NotSupportedException ("Remove operation is not supported.");
  1104. }
  1105. void IList.RemoveAt (int index)
  1106. {
  1107. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1108. }
  1109. public int IndexOf (ListViewItem item)
  1110. {
  1111. return list.IndexOf (item);
  1112. }
  1113. #endregion // Public Methods
  1114. } // SelectedListViewItemCollection
  1115. #endregion // Subclasses
  1116. }
  1117. }