Inheritance: System.ComponentModel.Component
示例#1
0
        /// <summary>
        /// Returns the cell to add to a row for the given value, depending on the type of column it will be 
        /// shown in.
        /// If the column is a TextColumn then just the Text property is set. For all other
        /// column types just the Data value is set.
        /// </summary>
        /// <param name="column"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        public virtual Cell GetCell(Column column, object val)
        {
            Cell cell = null;

            switch (column.GetType().Name)
            {
                case "TextColumn":
                    cell = new Cell(val.ToString());
                    break;

                case "CheckBoxColumn":
                    bool check = false;
                    if (val is Boolean)
                        check = (bool)val;
                    cell = new Cell("", check);
                    break;

                default:
                    cell = new Cell(val);
                    break;
            }

            return cell;
        }
示例#2
0
文件: Table.cs 项目: antiduh/XPTable
        /// <summary>
        /// Returns the new column width if the columns resize mode allows it to be changed.
        /// Returns 0 if it should not be changed.
        /// </summary>
        /// <param name="column"></param>
        /// <param name="maxwidth"></param>
        /// <returns></returns>
        int GetAutoColumnWidthWithMode(Column column, int maxwidth)
        {
            int changedWidth = 0;
            int oldwidth = column.Width;

            switch (column.AutoResizeMode)
            {
                case ColumnAutoResizeMode.Any:
                    // Always allow the change
                    changedWidth = maxwidth;
                    break;
                case ColumnAutoResizeMode.Shrink:
                    // Only allowed if the new width is smaller
                    if (maxwidth < oldwidth)
                        changedWidth = maxwidth;
                    break;
                case ColumnAutoResizeMode.Grow:
                    // Only allowed if the new width is greater
                    if (maxwidth > oldwidth)
                        changedWidth = maxwidth;
                    break;
            }

            return changedWidth;
        }
示例#3
0
        /// <summary>
        /// Returns a rectangle that contains the header of the specified column
        /// </summary>
        /// <param name="column">The column</param>
        /// <returns>A rectangle that countains the header of the specified column</returns>
        public Rectangle ColumnHeaderRect(Column column)
        {
            // check if we actually own the column
            int index = this.Columns.IndexOf(column);

            if (index == -1)
                return Rectangle.Empty;

            return this.ColumnHeaderRect(index);
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the Row class with an array of Column objects
        /// </summary>
        /// <param name="columns">An array of Cell objects that represent the Columns 
        /// of the ColumnModel</param>
        public ColumnModel(Column[] columns)
        {
            if (columns == null)
            {
                throw new ArgumentNullException("columns", "Column[] cannot be null");
            }

            this.Init();

            if (columns.Length > 0)
            {
                this.Columns.AddRange(columns);
            }
        }
		/// <summary>
		/// Adds the specified Column to the end of the collection
		/// </summary>
		/// <param name="column">The Column to add</param>
		public int Add(Column column)
		{
			if (column == null) 
			{
				throw new System.ArgumentNullException("Column is null");
			}

			int index = this.List.Add(column);
			
			this.RecalcWidthCache();

			this.OnColumnAdded(new ColumnModelEventArgs(this.owner, column, index, index));

			return index;
		}
		/// <summary>
		/// Removes an array of Column objects from the collection
		/// </summary>
		/// <param name="columns">An array of Column objects to remove 
		/// from the collection</param>
		public void RemoveRange(Column[] columns)
		{
			if (columns == null) 
			{
				throw new System.ArgumentNullException("Column[] is null");
			}

			for (int i=0; i<columns.Length; i++)
			{
				this.Remove(columns[i]);
			}
		}
示例#7
0
 /// <summary>
 /// Initializes a new instance of the ColumnEventArgs class with 
 /// the specified Column source, column index and event type
 /// </summary>
 /// <param name="source">The Column that Raised the event</param>
 /// <param name="index">The index of the Column</param>
 /// <param name="eventType">The type of event</param>
 /// <param name="oldValue">The old value of the changed property</param>
 public ColumnEventArgs(Column source, int index, ColumnEventType eventType, object oldValue)
     : base()
 {
     this.source = source;
     this.index = index;
     this.eventType = eventType;
     this.oldValue = oldValue;
 }
示例#8
0
		/// <summary>
		/// Returns the bounding rectangle of the specified column 
		/// in client coordinates
		/// </summary>
		/// <param name="column">The column</param>
		/// <returns>The bounding rectangle of the specified 
		/// column</returns>
		public Rectangle ColumnRect(Column column)
		{
			if (this.ColumnModel == null)
			{
				return Rectangle.Empty;
			}
			
			return this.ColumnRect(this.ColumnModel.Columns.IndexOf(column));
		}
示例#9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="column"></param>
 internal void SetColumn(Column column)
 {
     this.source = column;
 }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the ColumnEventArgs class with 
 /// the specified Column source, column index and event type
 /// </summary>
 /// <param name="source">The Column that Raised the event</param>
 /// <param name="eventType">The type of event</param>
 /// <param name="oldValue">The old value of the changed property</param>
 public ColumnEventArgs(Column source, ColumnEventType eventType, object oldValue)
     : this(source, -1, eventType, oldValue)
 {
 }
示例#11
0
 /// <summary>
 /// Creates a HeaderToolTipEventArgs using the values from args.
 /// </summary>
 /// <param name="column"></param>
 /// <param name="location"></param>
 public HeaderToolTipEventArgs(Column column, Point location)
     : base(false)
 {
     this.Column = column;
     this.Location = location;
     this.ToolTipText = column.ToolTipText;
 }
		/// <summary>
		/// Initializes a new instance of the HeaderMouseEventArgs class with 
		/// the specified source Column, Table, column index and column header bounds
		/// </summary>
		/// <param name="column">The Column that Raised the event</param>
		/// <param name="table">The Table the Column belongs to</param>
		/// <param name="index">The index of the Column</param>
		/// <param name="headerRect">The column header's bounding rectangle</param>
		public HeaderMouseEventArgs(Column column, Table table, int index, Rectangle headerRect) : base(MouseButtons.None, 0, -1, -1, 0)
		{
			this.column = column;
			this.table = table;
			this.index = index;
			this.headerRect = headerRect;
		} 
		/// <summary>
		/// Initializes a new instance of the HeaderMouseEventArgs class with 
		/// the specified source Column, Table, column index, column header bounds 
		/// and MouseEventArgs
		/// </summary>
		/// <param name="column">The Column that Raised the event</param>
		/// <param name="table">The Table the Column belongs to</param>
		/// <param name="index">The index of the Column</param>
		/// <param name="headerRect">The column header's bounding rectangle</param>
		/// <param name="mea">The MouseEventArgs that contains data about the 
		/// mouse event</param>
		public HeaderMouseEventArgs(Column column, Table table, int index, Rectangle headerRect, MouseEventArgs mea) : base(mea.Button, mea.Clicks, mea.X, mea.Y, mea.Delta)
		{
			this.column = column;
			this.table = table;
			this.index = index;
			this.headerRect = headerRect;
		} 
示例#14
0
文件: Table.cs 项目: antiduh/XPTable
        /// <summary>
        /// Sorts the specified column in the specified sort direction
        /// </summary>
        /// <param name="index">The index of the column to sort</param>
        /// <param name="column">The column to sort</param>
        /// <param name="sortOrder">The direction the column is to be sorted</param>
        /// <param name="stable">Specifies whether a stable sorting method 
        /// should be used to sort the column</param>
        private void Sort(int index, Column column, SortOrder sortOrder, bool stable)
        {
            // make sure a null comparer type doesn't sneak past

            ComparerBase comparer = null;

            if (column.Comparer != null)
            {
                comparer = (ComparerBase) Activator.CreateInstance(column.Comparer, new object[] { this.TableModel, index, sortOrder });
            }
            else if (column.DefaultComparerType != null)
            {
                comparer = (ComparerBase) Activator.CreateInstance(column.DefaultComparerType, new object[] { this.TableModel, index, sortOrder });
            }
            else
            {
                return;
            }

            column.InternalSortOrder = sortOrder;

            // create the comparer
            SorterBase sorter = null;

            // work out which sort method to use.
            // - InsertionSort/MergeSort are stable sorts,
            //   whereas ShellSort/HeapSort are unstable
            // - InsertionSort/ShellSort are faster than
            //   MergeSort/HeapSort on small lists and slower
            //   on large lists
            // so we choose based on the size of the list and
            // whether the user wants a stable sort
            if (this.SortType == SortType.AutoSort)
            {
                if (this.TableModel.Rows.Count < 1000)
                {
                    if (this.StableSort)
                        sorter = new InsertionSorter(this.TableModel, index, comparer, sortOrder);
                    else
                        sorter = new ShellSorter(this.TableModel, index, comparer, sortOrder);
                }
                else
                {
                    if (this.StableSort)
                        sorter = new MergeSorter(this.TableModel, index, comparer, sortOrder);
                    else
                        sorter = new HeapSorter(this.TableModel, index, comparer, sortOrder);
                }
            }
            else
            {
                switch (this.SortType)
                {
                    case SortType.HeapSort: { sorter = new HeapSorter(this.TableModel, index, comparer, sortOrder); break; }
                    case SortType.InsertionSort: { sorter = new InsertionSorter(this.TableModel, index, comparer, sortOrder); break; }
                    case SortType.MergeSort: { sorter = new MergeSorter(this.TableModel, index, comparer, sortOrder); break; }
                    case SortType.ShellSort: { sorter = new ShellSorter(this.TableModel, index, comparer, sortOrder); break; }
                    default: { throw new ApplicationException("Invalid Sort Type - " + this.SortType.ToString()); }
                }
            }

            sorter.SecondarySortOrders = this.ColumnModel.SecondarySortOrders;
            sorter.SecondaryComparers = this.GetSecondaryComparers(this.ColumnModel.SecondarySortOrders);

            // don't let the table redraw
            this.BeginUpdate();

            this.OnBeginSort(new ColumnEventArgs(column, index, ColumnEventType.Sorting, null));

            // Added by -= Micronn =- on 22 dec 2005
            Row focusedRow = null;

            if (this.FocusedCell != CellPos.Empty)
                focusedRow = this.tableModel.Rows[ this.FocusedCell.Row ];

            sorter.Sort();

            // Added by -= Micronn =- on 22 dec 2005
            if (focusedRow != null)
            {
                this.FocusedCell = new CellPos(focusedRow.Index, this.FocusedCell.Column);
                this.EnsureVisible(this.FocusedCell);
            }

            this.OnEndSort(new ColumnEventArgs(column, index, ColumnEventType.Sorting, null));

            // redraw any changes
            this.EndUpdate();
        }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the PaintHeaderEventArgs class with 
 /// the specified graphics, column, table, column index, header style 
 /// and clipping rectangle
 /// </summary>
 /// <param name="g">The Graphics used to paint the Column header</param>
 /// <param name="column">The Column to be painted</param>
 /// <param name="table">The Table the Column's ColumnModel belongs to</param>
 /// <param name="columnIndex">The index of the Column in the Table's ColumnModel</param>
 /// <param name="headerStyle">The style of the Column's header</param>
 /// <param name="headerRect">The Rectangle that represents the rectangle 
 /// in which to paint</param>
 public PaintHeaderEventArgs(Graphics g, Column column, Table table, int columnIndex, ColumnHeaderStyle headerStyle, Rectangle headerRect)
     : base(g, headerRect)
 {
     this.column = column;
     this.table = table;
     this.columnIndex = columnIndex;
     this.column = column;
     this.headerStyle = headerStyle;
     this.headerRect = headerRect;
     this.handled = false;
 }
		/// <summary>
		/// Initializes a new instance of the ColumnModelEventArgs class with 
		/// the specified ColumnModel source, start index, end index and affected Column
		/// </summary>
		/// <param name="source">The ColumnModel that originated the event</param>
		/// <param name="column">The affected Column</param>
		/// <param name="fromIndex">The start index of the affected Column(s)</param>
		/// <param name="toIndex">The end index of the affected Column(s)</param>
		public ColumnModelEventArgs(ColumnModel source, Column column, int fromIndex, int toIndex) : base()
		{
			this.source = source;
			this.column = column;
			this.fromIndex = fromIndex;
			this.toIndex = toIndex;
		}
示例#17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="column"></param>
 internal void SetColumn(Column column)
 {
     this.column = column;
 }
示例#18
0
		/// <summary>
		/// Sorts the specified column in the specified sort direction
		/// </summary>
		/// <param name="index">The index of the column to sort</param>
		/// <param name="column">The column to sort</param>
		/// <param name="sortOrder">The direction the column is to be sorted</param>
		/// <param name="stable">Specifies whether a stable sorting method 
		/// should be used to sort the column</param>
		private void Sort(int index, Column column, SortOrder sortOrder, bool stable)
		{
			// make sure a null comparer type doesn't sneak past
			
			ComparerBase comparer = null;
	
			if (column.Comparer != null)
			{
				comparer = (ComparerBase) Activator.CreateInstance(column.Comparer, new object[] {this.TableModel, index, sortOrder});
			}
			else if (column.DefaultComparerType != null)
			{
				comparer = (ComparerBase) Activator.CreateInstance(column.DefaultComparerType, new object[] {this.TableModel, index, sortOrder});
			}
			else
			{
				return;
			}

			column.InternalSortOrder = sortOrder;

			// create the comparer
			SorterBase sorter = null;

			// work out which sort method to use.
			// - InsertionSort/MergeSort are stable sorts, 
			//   whereas ShellSort/HeapSort are unstable
			// - InsertionSort/ShellSort are faster than 
			//   MergeSort/HeapSort on small lists and slower 
			//   on large lists
			// so we choose based on the size of the list and
			// whether the user wants a stable sort
			if (this.TableModel.Rows.Count < 1000)
			{
				if (stable)
				{
					sorter = new InsertionSorter(this.TableModel, index, comparer, sortOrder);
				}
				else
				{
					sorter = new ShellSorter(this.TableModel, index, comparer, sortOrder);
				}
			}
			else
			{
				if (stable)
				{
					sorter = new MergeSorter(this.TableModel, index, comparer, sortOrder);
				}
				else
				{
					sorter = new HeapSorter(this.TableModel, index, comparer, sortOrder);
				}
			}

			// don't let the table redraw
			this.BeginUpdate();

			this.OnBeginSort(new ColumnEventArgs(column, index, ColumnEventType.Sorting, null));

			sorter.Sort();

			this.OnEndSort(new ColumnEventArgs(column, index, ColumnEventType.Sorting, null));

			// redraw any changes
			this.EndUpdate();
		}
示例#19
0
文件: Demo.cs 项目: adarmus/XPTable
            public override Cell GetCell(Column column, object val)
            {
                Cell c;
                if (column.Text == "size")
                {
                    if (val is int)
                    {
                        int i = (int)val;
                        Image image = i < _list.Images.Count ? _list.Images[i] : null;
                        Cell cell = new Cell(val.ToString(), image);
                        c = cell;
                    }
                    else
                    {
                        throw new ApplicationException("Unexpected datatype " + val.GetType().ToString());
                    }
                }
                else
                {
                    c = base.GetCell(column, val);
                }
                c.CellStyle = new CellStyle();
                c.CellStyle.Font = new Font(_font.FontFamily, 10);

                //c.Font = new Font(c.Font.FontFamily, 18);
                return c;
            }
		/// <summary>
		/// Removes the specified Column from the model
		/// </summary>
		/// <param name="column">The Column to remove</param>
		public void Remove(Column column)
		{
			int columnIndex = this.IndexOf(column);

			if (columnIndex != -1) 
			{
				this.RemoveAt(columnIndex);
			}
		}
示例#21
0
        /// <summary>
        /// Initializes a new instance of the ColumnModel class with an array of strings 
        /// representing TextColumns
        /// </summary>
        /// <param name="columns">An array of strings that represent the Columns of 
        /// the ColumnModel</param>
        public ColumnModel(string[] columns)
        {
            if (columns == null)
            {
                throw new ArgumentNullException("columns", "string[] cannot be null");
            }

            this.Init();

            if (columns.Length > 0)
            {
                Column[] cols = new Column[columns.Length];

                for (int i=0; i<columns.Length; i++)
                {
                    cols[i] = new TextColumn(columns[i]);
                }

                this.Columns.AddRange(cols);
            }
        }
		/// <summary>
		///	Returns the index of the specified Column in the model
		/// </summary>
		/// <param name="column">The Column to look for</param>
		/// <returns>The index of the specified Column in the model</returns>
		public int IndexOf(Column column)
		{
			for (int i=0; i<this.Count; i++)
			{
				if (this[i] == column)
				{
					return i;
				}
			}

			return -1;
		}
示例#23
0
 /// <summary>
 /// Creates a new TextColumnFilter
 /// </summary>
 public TextColumnFilter(Column column)
 {
     Column = column;
     _allowedItems = null;
 }