| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
- //
- // Author:
- // Ravindra ([email protected])
- //
- // $Revision: 1.1 $
- // $Modtime: $
- // $Log: ListView.cs,v $
- // Revision 1.1 2004/09/30 13:24:25 ravindra
- // Initial implementation.
- //
- //
- // NOT COMPLETE
- //
- using System;
- using System.ComponentModel;
- using System.Collections;
- using System.Drawing;
- namespace System.Windows.Forms
- {
- public class ListView : Control
- {
- private ItemActivation activation = ItemActivation.Standard;
- private ListViewAlignment alignment = ListViewAlignment.Top;
- private bool allowColumnReorder = false;
- private bool autoArrange = true;
- private BorderStyle borderStyle = BorderStyle.Fixed3D;
- private bool checkBoxes = false;
- private CheckedIndexCollection checkedIndices;
- private CheckedListViewItemCollection checkedItems;
- private ColumnHeaderCollection columns;
- private ListViewItem focusedItem;
- private bool fullRowSelect = false;
- private bool gridLines = false;
- private ColumnHeaderStyle headerStyle = ColumnHeaderStyle.Clickable;
- private bool hideSelection = true;
- private bool hoverSelection = false;
- private ListViewItemCollection items;
- private bool labelEdit = false;
- private bool labelWrap = true;
- internal ImageList largeImageList;
- private IComparer itemSorter;
- private bool multiselect = true;
- private bool redraw = true;
- private bool scrollable = true;
- private SelectedIndexCollection selectedIndices;
- private SelectedListViewItemCollection selectedItems;
- internal ImageList smallImageList;
- private SortOrder sortOrder = SortOrder.None;
- private ImageList stateImageList;
- private bool updating = false;
- private View view = View.LargeIcon;
- #region Events
- public event LabelEditEventHandler AfterLabelEdit;
- public new event EventHandler BackgroundImageChanged;
- public event LabelEditEventHandler BeforeLabelEdit;
- public event ColumnClickEventHandler ColumnClick;
- public event EventHandler ItemActivate;
- public event ItemCheckEventHandler ItemCheck;
- public event ItemDragEventHandler ItemDrag;
- public new event PaintEventHandler Paint;
- public event EventHandler SelectedIndexChanged;
- public new event EventHandler TextChanged;
- #endregion // Events
- #region Public Constructors
- public ListView ()
- {
- checkedIndices = new CheckedIndexCollection (this);
- checkedItems = new CheckedListViewItemCollection (this);
- columns = new ColumnHeaderCollection (this);
- items = new ListViewItemCollection (this);
- selectedIndices = new SelectedIndexCollection (this);
- selectedItems = new SelectedListViewItemCollection (this);
- }
- #endregion // Public Constructors
- #region Protected Properties
- protected override CreateParams CreateParams {
- get { return base.CreateParams; }
- }
- protected override Size DefaultSize {
- get { return new Size (121, 97); }
- }
- #endregion // Protected Properties
- #region Public Instance Properties
- public ItemActivation Activation {
- get { return activation; }
- set { activation = value; }
- }
- public ListViewAlignment Alignment {
- get { return alignment; }
- set { alignment = value; }
- }
- public bool AllowColumnReorder {
- get { return allowColumnReorder; }
- set { allowColumnReorder = value; }
- }
- public bool AutoArrange {
- get { return autoArrange; }
- set { autoArrange = value; }
- }
- public override Color BackColor {
- get { return base.BackColor; }
- set { base.BackColor = value; }
- }
- public override Image BackgroundImage {
- get { return background_image; }
- set {
- if (value == background_image)
- return;
- background_image = value;
- if (BackgroundImageChanged != null)
- BackgroundImageChanged (this, new EventArgs ());
- }
- }
- public BorderStyle BorderStyle {
- get { return borderStyle; }
- set { borderStyle = value; }
- }
- public bool CheckBoxes {
- get { return checkBoxes; }
- set { checkBoxes = value; }
- }
- public CheckedIndexCollection CheckedIndices {
- get { return checkedIndices; }
- }
- public CheckedListViewItemCollection CheckedItems {
- get { return checkedItems; }
- }
- public ColumnHeaderCollection Columns {
- get { return columns; }
- }
- public ListViewItem FocusedItem {
- get { return focusedItem; }
- }
- public override Color ForeColor {
- get { return base.ForeColor; }
- set { base.ForeColor = value; }
- }
- public bool FullRowSelect {
- get { return fullRowSelect; }
- set { fullRowSelect = value; }
- }
- public bool GridLines {
- get { return gridLines; }
- set { gridLines = value; }
- }
- public ColumnHeaderStyle HeaderStyle {
- get { return headerStyle; }
- set { headerStyle = value; }
- }
- public bool HideSelection {
- get { return hideSelection; }
- set { hideSelection = value; }
- }
- public bool HoverSelection {
- get { return hoverSelection; }
- set { hoverSelection = value; }
- }
- public ListViewItemCollection Items {
- get { return items; }
- }
- public bool LabelEdit {
- get { return labelEdit; }
- set { labelEdit = value; }
- }
- public bool LabelWrap {
- get { return labelWrap; }
- set { labelWrap = value; }
- }
- public ImageList LargeImageList {
- get { return largeImageList; }
- set { largeImageList = value; }
- }
- public IComparer ListViewItemSorter {
- get { return itemSorter; }
- set { itemSorter = value; }
- }
- public bool MultiSelect {
- get { return multiselect; }
- set { multiselect = value; }
- }
- public bool Scrollable {
- get { return scrollable; }
- set { scrollable = value; }
- }
- public SelectedIndexCollection SelectedIndices {
- get { return selectedIndices; }
- }
- public SelectedListViewItemCollection SelectedItems {
- get { return selectedItems; }
- }
- public ImageList SmallImageList {
- get { return smallImageList; }
- set { smallImageList = value; }
- }
- public SortOrder Sorting {
- get { return sortOrder; }
- set { sortOrder = value; }
- }
- public ImageList StateImageList {
- get { return stateImageList; }
- set { stateImageList = value; }
- }
- public override string Text {
- get { return text; }
- set {
- if (value == text)
- return;
- text = value;
- if (TextChanged != null)
- TextChanged (this, new EventArgs ());
- }
- }
- public ListViewItem TopItem {
- get { return items [0]; }
- }
- public View View {
- get { return view; }
- set { view = value; }
- }
- #endregion // Public Instance Properties
- #region Internal Methods
- internal void Redraw (bool recalculate)
- {
- if (recalculate)
- CalculateListView ();
- redraw = true;
- }
- private void CalculateListView ()
- {
- // FIXME: TODO
- }
- #endregion // Internal Methods
- #region Protected Methods
- protected override void CreateHandle ()
- {
- base.CreateHandle ();
- }
- protected override void Dispose (bool disposing)
- {
- Clear ();
- }
- protected override bool IsInputKey (Keys keyData)
- {
- return base.IsInputKey (keyData);
- }
- protected virtual void OnAfterLabelEdit (LabelEditEventArgs e)
- {
- if (AfterLabelEdit != null)
- AfterLabelEdit (this, e);
- }
- protected virtual void OnBeforeLabelEdit (LabelEditEventArgs e)
- {
- if (BeforeLabelEdit != null)
- BeforeLabelEdit (this, e);
- }
- protected virtual void OnColumnClick (ColumnClickEventArgs e)
- {
- if (ColumnClick != null)
- ColumnClick (this, e);
- }
- protected override void OnEnabledChanged (EventArgs e)
- {
- base.OnEnabledChanged (e);
- }
- protected override void OnFontChanged (EventArgs e)
- {
- base.OnFontChanged (e);
- }
- protected override void OnHandleCreated (EventArgs e)
- {
- base.OnHandleCreated (e);
- }
- protected override void OnHandleDestroyed (EventArgs e)
- {
- base.OnHandleDestroyed (e);
- }
- protected virtual void OnItemActivate (EventArgs e)
- {
- if (ItemActivate != null)
- ItemActivate (this, e);
- }
- protected virtual void OnItemCheck (ItemCheckEventArgs ice)
- {
- if (ItemCheck != null)
- ItemCheck (this, ice);
- }
- protected virtual void OnItemDrag (ItemDragEventArgs e)
- {
- if (ItemDrag != null)
- ItemDrag (this, e);
- }
- protected virtual void OnSelectedIndexChanged (EventArgs e)
- {
- if (SelectedIndexChanged != null)
- SelectedIndexChanged (this, e);
- }
- protected override void OnSystemColorsChanged (EventArgs e)
- {
- base.OnSystemColorsChanged (e);
- }
- protected void RealizeProperties ()
- {
- // FIXME: TODO
- }
- protected void UpdateExtendedStyles ()
- {
- // FIXME: TODO
- }
- protected override void WndProc (ref Message m)
- {
- base.WndProc (ref m);
- }
- #endregion // Protected Methods
- #region Public Instance Methods
- public void ArrangeIcons ()
- {
- ArrangeIcons (ListViewAlignment.Default);
- }
- public void ArrangeIcons (ListViewAlignment alignment)
- {
- // Icons are arranged only if view is set to LargeIcon or SmallIcon
- if (view == View.LargeIcon || view == View.SmallIcon) {
- // FIXME: TODO
- }
- }
- public void BeginUpdate ()
- {
- // flag to avoid painting
- updating = true;
- }
- public void Clear ()
- {
- columns.Clear ();
- items.Clear ();
- }
- public void EndUpdate ()
- {
- // flag to avoid painting
- updating = false;
- }
- public void EnsureVisible (int index)
- {
- // FIXME: TODO
- }
-
- public ListViewItem GetItemAt (int x, int y)
- {
- foreach (ListViewItem item in items) {
- if (item.Bounds.Contains (x, y))
- return item;
- }
- return null;
- }
- public Rectangle GetItemRect (int index)
- {
- return GetItemRect (index, ItemBoundsPortion.Entire);
- }
- public Rectangle GetItemRect (int index, ItemBoundsPortion portion)
- {
- if (index < 0 || index >= items.Count)
- throw new IndexOutOfRangeException ("Invalid Index");
- return items [index].GetBounds (portion);
- }
- public void Sort ()
- {
- if (sortOrder != SortOrder.None)
- items.list.Sort (itemSorter);
- if (sortOrder == SortOrder.Descending)
- items.list.Reverse ();
- }
- public override string ToString ()
- {
- int count = this.Items.Count;
- if (count == 0)
- return string.Format ("System.Windows.Forms.ListView, Items.Count: 0");
- else
- return string.Format ("System.Windows.Forms.ListView, Items.Count: {0}, Items[0]: {1}", count, this.Items [0].ToString ());
- }
- #endregion // Public Instance Methods
- #region Subclasses
- public class CheckedIndexCollection : IList, ICollection, IEnumerable
- {
- internal ArrayList list;
- private ListView owner;
- #region Public Constructor
- public CheckedIndexCollection (ListView owner)
- {
- list = new ArrayList ();
- this.owner = owner;
- }
- #endregion // Public Constructor
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return true; }
- }
- public int this [int index] {
- get {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- return (int) list [index];
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set { throw new NotSupportedException ("SetItem operation is not supported."); }
- }
- #endregion // Public Properties
- #region Public Methods
- public bool Contains (int checkedIndex)
- {
- return list.Contains (checkedIndex);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- void ICollection.CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- int IList.Add (object value)
- {
- throw new NotSupportedException ("Add operation is not supported.");
- }
- void IList.Clear ()
- {
- throw new NotSupportedException ("Clear operation is not supported.");
- }
- bool IList.Contains (object checkedIndex)
- {
- return list.Contains (checkedIndex);
- }
- int IList.IndexOf (object checkedIndex)
- {
- return list.IndexOf (checkedIndex);
- }
- void IList.Insert (int index, object value)
- {
- throw new NotSupportedException ("Insert operation is not supported.");
- }
- void IList.Remove (object value)
- {
- throw new NotSupportedException ("Remove operation is not supported.");
- }
- void IList.RemoveAt (int index)
- {
- throw new NotSupportedException ("RemoveAt operation is not supported.");
- }
- public int IndexOf (int checkedIndex)
- {
- return list.IndexOf (checkedIndex);
- }
- #endregion // Public Methods
- } // CheckedIndexCollection
- public class CheckedListViewItemCollection : IList, ICollection, IEnumerable
- {
- internal ArrayList list;
- private ListView owner;
- #region Public Constructor
- public CheckedListViewItemCollection (ListView owner)
- {
- list = new ArrayList ();
- this.owner = owner;
- }
- #endregion // Public Constructor
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return true; }
- }
- public ListViewItem this [int index] {
- get {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- return (ListViewItem) list [index];
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set { throw new NotSupportedException ("SetItem operation is not supported."); }
- }
- #endregion // Public Properties
- #region Public Methods
- public bool Contains (ListViewItem item)
- {
- return list.Contains (item);
- }
- public virtual void CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- int IList.Add (object value)
- {
- throw new NotSupportedException ("Add operation is not supported.");
- }
- void IList.Clear ()
- {
- throw new NotSupportedException ("Clear operation is not supported.");
- }
- bool IList.Contains (object item)
- {
- return list.Contains (item);
- }
- int IList.IndexOf (object item)
- {
- return list.IndexOf (item);
- }
- void IList.Insert (int index, object value)
- {
- throw new NotSupportedException ("Insert operation is not supported.");
- }
- void IList.Remove (object value)
- {
- throw new NotSupportedException ("Remove operation is not supported.");
- }
- void IList.RemoveAt (int index)
- {
- throw new NotSupportedException ("RemoveAt operation is not supported.");
- }
- public int IndexOf (ListViewItem item)
- {
- return list.IndexOf (item);
- }
- #endregion // Public Methods
- } // CheckedListViewItemCollection
- public class ColumnHeaderCollection : IList, ICollection, IEnumerable
- {
- internal ArrayList list;
- private ListView owner;
- #region Public Constructor
- public ColumnHeaderCollection (ListView owner)
- {
- list = new ArrayList ();
- this.owner = owner;
- }
- #endregion // Public Constructor
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return false; }
- }
- public virtual ColumnHeader this [int index] {
- get {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- return (ColumnHeader) list [index];
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set { throw new NotSupportedException ("SetItem operation is not supported."); }
- }
- #endregion // Public Properties
- #region Public Methods
- public virtual int Add (ColumnHeader value)
- {
- return list.Add (value);
- }
- public virtual ColumnHeader Add (string str, int width, HorizontalAlignment textAlign)
- {
- ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
- this.Add (colHeader);
- return colHeader;
- }
- public virtual void AddRange (ColumnHeader [] values)
- {
- foreach (ColumnHeader colHeader in values)
- this.Add (colHeader);
- }
- public virtual void Clear ()
- {
- list.Clear ();
- }
- public bool Contains (ColumnHeader value)
- {
- return list.Contains (value);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- void ICollection.CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- int IList.Add (object value)
- {
- if (! (value is ColumnHeader)) {
- throw new ArgumentException("Not of type ColumnHeader", "value");
- }
- return this.Add ((ColumnHeader) value);
- }
- bool IList.Contains (object value)
- {
- if (! (value is ColumnHeader)) {
- throw new ArgumentException("Not of type ColumnHeader", "value");
- }
- return this.Contains ((ColumnHeader) value);
- }
- int IList.IndexOf (object value)
- {
- if (! (value is ColumnHeader)) {
- throw new ArgumentException("Not of type ColumnHeader", "value");
- }
- return this.IndexOf ((ColumnHeader) value);
- }
- void IList.Insert (int index, object value)
- {
- if (! (value is ColumnHeader)) {
- throw new ArgumentException("Not of type ColumnHeader", "value");
- }
- this.Insert (index, (ColumnHeader) value);
- }
- void IList.Remove (object value)
- {
- if (! (value is ColumnHeader)) {
- throw new ArgumentException("Not of type ColumnHeader", "value");
- }
- this.Remove ((ColumnHeader) value);
- }
- public int IndexOf (ColumnHeader value)
- {
- return list.IndexOf (value);
- }
- public void Insert (int index, ColumnHeader value)
- {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- list.Insert (index, value);
- }
- public void Insert (int index, string str, int width, HorizontalAlignment textAlign)
- {
- ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
- this.Insert (index, colHeader);
- }
- public virtual void Remove (ColumnHeader column)
- {
- list.Remove (column);
- }
- public virtual void RemoveAt (int index)
- {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- list.RemoveAt (index);
- }
- #endregion // Public Methods
- } // ColumnHeaderCollection
- public class ListViewItemCollection : IList, ICollection, IEnumerable
- {
- internal ArrayList list;
- private ListView owner;
- #region Public Constructor
- public ListViewItemCollection (ListView owner)
- {
- list = new ArrayList ();
- this.owner = owner;
- }
- #endregion // Public Constructor
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return false; }
- }
- public virtual ListViewItem this [int displayIndex] {
- get {
- if (displayIndex < 0 || displayIndex >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- return (ListViewItem) list [displayIndex];
- }
- set {
- if (displayIndex < 0 || displayIndex >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- value.owner = this.owner;
- list [displayIndex] = value;
- owner.Redraw (true);
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set {
- if (value is ListViewItem)
- this [index] = (ListViewItem) value;
- else
- this [index] = new ListViewItem (value.ToString ());
- }
- }
- #endregion // Public Properties
- #region Public Methods
- public virtual ListViewItem Add (ListViewItem value)
- {
- value.owner = this.owner;
- list.Add (value);
- if (owner.Sorting != SortOrder.None)
- owner.Sort ();
- owner.Redraw (true);
- return value;
- }
- public virtual ListViewItem Add (string text)
- {
- ListViewItem item = new ListViewItem (text);
- return this.Add (item);
- }
- public virtual ListViewItem Add (string text, int imageIndex)
- {
- ListViewItem item = new ListViewItem (text, imageIndex);
- return this.Add (item);
- }
- public void AddRange (ListViewItem [] values)
- {
- list.Clear ();
- foreach (ListViewItem item in values) {
- item.owner = this.owner;
- list.Add (item);
- }
- if (owner.Sorting != SortOrder.None)
- owner.Sort ();
- owner.Redraw (true);
- }
- public virtual void Clear ()
- {
- list.Clear ();
- owner.Redraw (true);
- }
- public bool Contains (ListViewItem item)
- {
- return list.Contains (item);
- }
- public virtual void CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- int IList.Add (object item)
- {
- int result;
- ListViewItem li;
- if (item is ListViewItem)
- li = (ListViewItem) item;
- else
- li = new ListViewItem (item.ToString ());
- li.owner = this.owner;
- result = list.Add (li);
- owner.Redraw (true);
- return result;
- }
- bool IList.Contains (object item)
- {
- return list.Contains (item);
- }
- int IList.IndexOf (object item)
- {
- return list.IndexOf (item);
- }
- void IList.Insert (int index, object item)
- {
- if (item is ListViewItem)
- this.Insert (index, (ListViewItem) item);
- else
- this.Insert (index, item.ToString ());
- }
- void IList.Remove (object item)
- {
- if (list.Contains (item)) {
- list.Remove (item);
- owner.Redraw (true);
- }
- }
- public int IndexOf (ListViewItem item)
- {
- return list.IndexOf (item);
- }
- public ListViewItem Insert (int index, ListViewItem item)
- {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- item.owner = this.owner;
- list.Insert (index, item);
- owner.Redraw (true);
- return item;
- }
- public ListViewItem Insert (int index, string text)
- {
- return this.Insert (index, new ListViewItem (text));
- }
- public ListViewItem Insert (int index, string text, int imageIndex)
- {
- return this.Insert (index, new ListViewItem (text, imageIndex));
- }
- public virtual void Remove (ListViewItem item)
- {
- if (list.Contains (item)) {
- list.Remove (item);
- owner.Redraw (true);
- }
- }
- public virtual void RemoveAt (int index)
- {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- list.RemoveAt (index);
- owner.Redraw (false);
- }
- #endregion // Public Methods
- } // ListViewItemCollection
- public class SelectedIndexCollection : IList, ICollection, IEnumerable
- {
- internal ArrayList list;
- private ListView owner;
- #region Public Constructor
- public SelectedIndexCollection (ListView owner)
- {
- list = new ArrayList ();
- this.owner = owner;
- }
- #endregion // Public Constructor
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return true; }
- }
- public int this [int index] {
- get {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- return (int) list [index];
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set { throw new NotSupportedException ("SetItem operation is not supported."); }
- }
- #endregion // Public Properties
- #region Public Methods
- public bool Contains (int selectedIndex)
- {
- return list.Contains (selectedIndex);
- }
- public virtual void CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- int IList.Add (object value)
- {
- throw new NotSupportedException ("Add operation is not supported.");
- }
- void IList.Clear ()
- {
- throw new NotSupportedException ("Clear operation is not supported.");
- }
- bool IList.Contains (object selectedIndex)
- {
- return list.Contains (selectedIndex);
- }
- int IList.IndexOf (object selectedIndex)
- {
- return list.IndexOf (selectedIndex);
- }
- void IList.Insert (int index, object value)
- {
- throw new NotSupportedException ("Insert operation is not supported.");
- }
- void IList.Remove (object value)
- {
- throw new NotSupportedException ("Remove operation is not supported.");
- }
- void IList.RemoveAt (int index)
- {
- throw new NotSupportedException ("RemoveAt operation is not supported.");
- }
- public int IndexOf (int selectedIndex)
- {
- return list.IndexOf (selectedIndex);
- }
- #endregion // Public Methods
- } // SelectedIndexCollection
- public class SelectedListViewItemCollection : IList, ICollection, IEnumerable
- {
- internal ArrayList list;
- private ListView owner;
- #region Public Constructor
- public SelectedListViewItemCollection (ListView owner)
- {
- list = new ArrayList ();
- this.owner = owner;
- }
- #endregion // Public Constructor
- #region Public Properties
- public virtual int Count {
- get { return list.Count; }
- }
- public virtual bool IsReadOnly {
- get { return true; }
- }
- public ListViewItem this [int index] {
- get {
- if (index < 0 || index >= list.Count)
- throw new ArgumentOutOfRangeException ("Index out of range.");
- return (ListViewItem) list [index];
- }
- }
- bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
- }
- object ICollection.SyncRoot {
- get { return list.SyncRoot; }
- }
- bool IList.IsFixedSize {
- get { return list.IsFixedSize; }
- }
- object IList.this [int index] {
- get { return this [index]; }
- set { throw new NotSupportedException ("SetItem operation is not supported."); }
- }
- #endregion // Public Properties
- #region Public Methods
- public virtual void Clear ()
- {
- list.Clear ();
- }
- public bool Contains (ListViewItem item)
- {
- return list.Contains (item);
- }
- public virtual void CopyTo (Array dest, int index)
- {
- list.CopyTo (dest, index);
- }
- public virtual IEnumerator GetEnumerator ()
- {
- return list.GetEnumerator ();
- }
- int IList.Add (object value)
- {
- throw new NotSupportedException ("Add operation is not supported.");
- }
- bool IList.Contains (object item)
- {
- return list.Contains (item);
- }
- int IList.IndexOf (object item)
- {
- return list.IndexOf (item);
- }
- void IList.Insert (int index, object value)
- {
- throw new NotSupportedException ("Insert operation is not supported.");
- }
- void IList.Remove (object value)
- {
- throw new NotSupportedException ("Remove operation is not supported.");
- }
- void IList.RemoveAt (int index)
- {
- throw new NotSupportedException ("RemoveAt operation is not supported.");
- }
- public int IndexOf (ListViewItem item)
- {
- return list.IndexOf (item);
- }
- #endregion // Public Methods
- } // SelectedListViewItemCollection
- #endregion // Subclasses
- }
- }
|