internal void SetDisplayIndex(TreeListViewColumnHeader column, int newDisplayIndex) { if (!Contains(column)) { return; } if (newDisplayIndex >= Count) { newDisplayIndex = Count - 1; } int curDisplayIndex = column.DisplayIndex; if (curDisplayIndex == newDisplayIndex) { return; } _logicalData.RemoveAt(curDisplayIndex); _logicalData.Insert(newDisplayIndex, column); if (_listView != null) { _listView.ColumnInvalidated(null, false, true); } }
/// <summary> /// Inserts an existing <see cref="TreeListViewColumnHeader"/> into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index location where the column is inserted.</param> /// <param name="column">The <see cref="TreeListViewColumnHeader"/> that represents the column to insert.</param> public void Insert(int index, TreeListViewColumnHeader column) { if (column == null) { throw new ArgumentNullException("column"); } lock (_physicalData.SyncRoot) { _physicalData.Insert(index, column); _logicalData.Add(column); column.Collection = this; } if (ListView != null) { //create a new subitem foreach (TreeListViewItem item in ListView.Items) { item.SubItems.InternalInsert(index, new TreeListViewSubItem(index)); } //recalculate layout and redraw ListView.ColumnInvalidated(column, true, true); } }
private void OnTreeListViewResized(object sender, EventArgs e) { TreeListViewColumnHeader headerAutoSize = null; foreach (TreeListViewColumnHeader header in _physicalData) { if (header.WidthBehavior == ColumnWidthBehavior.Fill) { headerAutoSize = header; break; } } if (headerAutoSize != null) { int cumulativeColumnWidth = 0; for (int x = 0; x < _physicalData.Count; ++x) { if (_physicalData[x] != headerAutoSize) { cumulativeColumnWidth += (_physicalData[x] as TreeListViewColumnHeader).Width; } } int autoSizeWidth = _listView.Width - cumulativeColumnWidth - 2; headerAutoSize.Width = autoSizeWidth > headerAutoSize.MinimumWidth ? autoSizeWidth : headerAutoSize.MinimumWidth; } }
/// <summary> /// Creates an identical copy of the current <see cref="TreeListViewColumnHeader" /> that is not attached to a <see cref="TreeListView"/>. /// </summary> /// <returns>An object representing a copy of this <see cref="TreeListViewColumnHeader"/> object.</returns> public TreeListViewColumnHeader Clone() { TreeListViewColumnHeader ch = new TreeListViewColumnHeader(); ch._text = _text; ch._contentAlign = _contentAlign; ch._foregroundBrush = _foregroundBrush; ch._font = _font; ch._width = _width; ch._maximumWidth = _maximumWidth; ch._minimumWidth = _minimumWidth; ch._visible = _visible; ch._sortDataType = _sortDataType; ch._defaultSortOrder = _defaultSortOrder; ch._customSort = _customSort; ch._sortOrder = _sortOrder; ch._customSortTag = _customSortTag; ch._tag = _tag; ch._toolTip = _toolTip; if (_image != null) { ch._image = _image.Clone() as Image; } return(ch); }
/// <summary> /// Creates a new header and inserts it into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index location where the column is inserted.</param> /// <param name="text">The text to display.</param> /// <param name="width">The starting width.</param> /// <param name="contentAlign">The content alignment.</param> /// <returns>The <see cref="TreeListViewColumnHeader"/> that was inserted into the collection.</returns> public TreeListViewColumnHeader Insert(int index, string text, int width, ContentAlignment contentAlign) { TreeListViewColumnHeader column = new TreeListViewColumnHeader(text, width, contentAlign); Insert(index, column); return(column); }
// Aulofee customization - end /// <summary> /// Creates a new header and inserts it into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index location where the column is inserted.</param> /// <param name="text">The text to display.</param> /// <param name="width">The starting width.</param> /// <param name="horizontalAlign">The horizontal alignment of the text, will default vertical alignment to middle.</param> /// <returns>The <see cref="TreeListViewColumnHeader"/> that was inserted into the collection.</returns> public TreeListViewColumnHeader Insert(int index, string text, int width, HorizontalAlignment horizontalAlign) { TreeListViewColumnHeader column = new TreeListViewColumnHeader(text, width, horizontalAlign); Insert(index, column); return(column); }
/// <summary> /// Creates a new header and inserts it into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index location where the column is inserted.</param> /// <param name="text">The text to display.</param> /// <param name="width">The starting width.</param> /// <returns>The <see cref="TreeListViewColumnHeader"/> that was inserted into the collection.</returns> public TreeListViewColumnHeader Insert(int index, string text, int width) { TreeListViewColumnHeader column = new TreeListViewColumnHeader(text, width); Insert(index, column); return(column); }
/// <summary> /// Adds an existing <see cref="TreeListViewColumnHeader"/> object to the collection. /// </summary> /// <param name="column">The <b>TreeListViewColumnHeader</b> object to add to the collection.</param> /// <returns>The position into which the new element was inserted.</returns> public int Add(TreeListViewColumnHeader column) { int index = _physicalData.Count; Insert(index, column); return(index); }
// Aulofee customization - start. Method added (can directly specify the sort type) /// <summary> /// Creates a new header and inserts it into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index location where the column is inserted.</param> /// <param name="text">The text to display.</param> /// <param name="width">The starting width.</param> /// <param name="sortDataType">The data type to use to sort the column.</param> /// <returns>The <see cref="TreeListViewColumnHeader"/> that was inserted into the collection.</returns> public TreeListViewColumnHeader Insert(int index, string text, int width, SortDataType sortDataType) { TreeListViewColumnHeader column = new TreeListViewColumnHeader(text, width); column.SortDataType = sortDataType; Insert(index, column); return(column); }
/// <summary> /// Gets or sets the <see cref="TreeListViewColumnHeader"/> at the specified index. /// In C#, this property is the indexer for the <b>TreeListViewColumnHeaderCollection</b> class. /// </summary> /// <value>The <see cref="TreeListViewColumnHeader"/> at the specified index.</value> public TreeListViewColumnHeader this[int index] { get { return(_physicalData[index] as TreeListViewColumnHeader); } set { if (value == null) { throw new ArgumentNullException("value", "TreeListView cannot contain null TreeListViewColumnHeaders"); } if (value == _physicalData[index]) { return; } TreeListViewColumnHeader currentColumn = this[index]; if (value.Collection == this) // incoming column is part of this collection already { // just swap them, display index will stay the same _physicalData[value.Index] = currentColumn; _physicalData[index] = value; } else { // let the current column know they they don't belong to us anymore currentColumn.Collection = null; if (value.Collection != null) // incoming column is part of a different collection, remove it from that collection { value.Collection.Remove(value); } _physicalData[index] = value; _logicalData[index] = value; value.Collection = this; } } }
/// <summary> /// Removes the specified <see cref="TreeListViewColumnHeader"/> from the collection. /// </summary> /// <param name="column">A <see cref="TreeListViewColumnHeader"/> to remove from the collection.</param> /// <param name="removeSubItems"><b>True</b> if you want to remove the subitems, <b>false</b> otherwise.</param> public void Remove(TreeListViewColumnHeader column, bool removeSubItems) { if (column == null) { return; } lock (_physicalData.SyncRoot) { if (_listView != null) { if (removeSubItems) { //remove subitems foreach (TreeListViewItem item in _listView.Items) { item.RemoveSubItem(column.Index); } } else { //hide subitem controls foreach (TreeListViewItem item in _listView.Items) { Control subItemControl = item.SubItems[column.Index].ItemControl; if (subItemControl != null) { subItemControl.Visible = false; } } } } _physicalData.Remove(column); _logicalData.Remove(column); column.Collection = null; } if (ListView != null) { ListView.ColumnInvalidated(column, true, true); } }
/// <summary> /// Compares the two incoming <see cref="TreeListViewItem"/> elements. /// </summary> /// <param name="item1">The first item to compare.</param> /// <param name="item2">The second item to compare.</param> /// <returns>Zero if equal, -1 if item1 < item2, 1 if item1 > item2</returns> public int Compare(TreeListViewItem item1, TreeListViewItem item2) { for (int index = 0; index < _sortColumns.Length; ++index) { // cache these values so as to make all of this a little bit faster TreeListViewColumnHeader sortColumn = _sortColumns[index]; int sortColumnIndex = _sortColumnIndices[index]; SortOrder sortOrder = sortColumn.SortOrder; SortDataType sortDataType = sortColumn.SortDataType; if (item1 == null || item2 == null || sortOrder == SortOrder.None || sortDataType == SortDataType.None) { return(0); // We don't know type, the order, or the data - so both objects are same for us } int n = 0; TreeListViewSubItem subItem1 = sortOrder == SortOrder.Ascending ? item1.SubItems[sortColumnIndex] : item2.SubItems[sortColumnIndex]; TreeListViewSubItem subItem2 = sortOrder == SortOrder.Ascending ? item2.SubItems[sortColumnIndex] : item1.SubItems[sortColumnIndex]; if (sortDataType == SortDataType.Custom) { n = sortColumn.CustomSortComparer.Compare(subItem1, subItem2); } else { n = CompareItems(subItem1.Text, subItem2.Text, sortDataType); } if (n != 0) { return(n); } } return(0); }
/// <summary> /// Determines whether the specified column is located in the collection. /// </summary> /// <param name="column">A <see cref="TreeListViewColumnHeader"/> representing the column to locate in the collection.</param> /// <returns><b>true</b> if the column is contained in the collection; otherwise, <b>false</b>.</returns> public bool Contains(TreeListViewColumnHeader column) { return(_physicalData.Contains(column)); }
/// <summary> /// Returns the display index of the specified column. /// </summary> /// <param name="column">A <see cref="TreeListViewHeader"/> representing the column to locate.</param> /// <returns>The zero-based display index of the column's location in the collection. If the column is not located in the collection the return value is negative one (-1).</returns> public int DisplayIndexOf(TreeListViewColumnHeader column) { return(_logicalData.IndexOf(column)); }
/// <summary> /// Returns the index within the collection of the specified column. /// </summary> /// <param name="column">A <see cref="TreeListViewColumnHeader"/> representing the column to locate in the collection.</param> /// <returns>The zero-based index of the column's location in the collection. If the column is not located in the collection the return value is negative one (-1).</returns> public int IndexOf(TreeListViewColumnHeader column) { return(_physicalData.IndexOf(column)); }
/// <summary> /// Removes the specified <see cref="TreeListViewColumnHeader"/> from the collection. /// </summary> /// <param name="column">A <see cref="TreeListViewColumnHeader"/> to remove from the collection.</param> public void Remove(TreeListViewColumnHeader column) { Remove(column, false); }