diff options
Diffstat (limited to 'mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs')
-rw-r--r-- | mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs | 387 |
1 files changed, 387 insertions, 0 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs new file mode 100644 index 00000000000..59f4669d6fe --- /dev/null +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewColumn.cs @@ -0,0 +1,387 @@ +// 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) 2005 Novell, Inc. (http://www.novell.com) +// +// Author: +// Pedro MartÃnez Juliá <pedromj@gmail.com> +// + + +#if NET_2_0 + +using System; +using System.ComponentModel; + +namespace System.Windows.Forms { + + public class DataGridViewColumn : DataGridViewBand, IComponent, IDisposable { + + private DataGridViewAutoSizeColumnMode autoSizeMode; + private DataGridViewCell cellTemplate; + //private ContextMenuStrip contextMenuStrip; + private string dataPropertyName; + private int displayIndex; + private int dividerWidth; + private float fillWeight; + private bool frozen; + private DataGridViewColumnHeaderCell headerCell; + private string headerText = ""; + private DataGridViewAutoSizeColumnMode inheritedAutoSizeMode; + private bool isDataBound; + private int minimumWidth = 5; + private string name = ""; + private bool readOnly; + private DataGridViewTriState resizable = DataGridViewTriState.True; + private ISite site; + private DataGridViewColumnSortMode sortMode; + private string toolTipText; + private Type valueType; + private bool visible = true; + private int width = 100; + + public DataGridViewColumn () { + cellTemplate = null; + base.DefaultCellStyle = new DataGridViewCellStyle(); + readOnly = false; + headerCell = new DataGridViewColumnHeaderCell(); + headerCell.SetColumnIndex(Index); + displayIndex = -1; + } + + public DataGridViewColumn (DataGridViewCell cellTemplate) : this () { + this.cellTemplate = (DataGridViewCell) cellTemplate.Clone(); + } + + public DataGridViewAutoSizeColumnMode AutoSizeMode { + get { return autoSizeMode; } + set { autoSizeMode = value; } + } + + public virtual DataGridViewCell CellTemplate { + get { return cellTemplate; } + set { + cellTemplate = value; + if (DataGridView != null) { + cellTemplate.SetDataGridView(DataGridView); + } + } + } + + public Type CellType { + get { + if (cellTemplate == null) { + return null; + } + return cellTemplate.GetType(); + } + } + + /* + public override ContextMenuStrip ContextMenuStrip { + get { return contextMenuStrip; } + set { + if (contextMenuStrip != value) { + contextMenuStrip = value; + if (DataGridView != null) { + DataGridView.OnColumnContextMenuStripChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + */ + + public string DataPropertyName { + get { return dataPropertyName; } + set { + if (dataPropertyName != value) { + dataPropertyName = value; + if (DataGridView != null) { + DataGridView.OnColumnDataPropertyNameChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public override DataGridViewCellStyle DefaultCellStyle { + get { + return base.DefaultCellStyle; + } + set { + if (DefaultCellStyle != value) { + base.DefaultCellStyle = value; + if (DataGridView != null) { + DataGridView.OnColumnDefaultCellStyleChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public int DisplayIndex { + get { + if (displayIndex < 0) { + return Index; + } + return displayIndex; + } + set { + if (displayIndex != value) { + if (value < 0 || value > Int32.MaxValue) { + throw new ArgumentOutOfRangeException("DisplayIndex is out of range"); + } + displayIndex = value; + if (DataGridView != null) { + DataGridView.OnColumnDisplayIndexChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public int DividerWidth { + get { return dividerWidth; } + set { + if (dividerWidth != value) { + dividerWidth = value; + if (DataGridView != null) { + DataGridView.OnColumnDividerWidthChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public float FillWeight { + get { return fillWeight; } + set { + fillWeight = value; + /* When the System.Windows.Forms.DataGridViewColumn.InheritedAutoSizeMode property value is System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill, the column is resized along with other columns in that mode so that all visible columns in the control exactly fill the horizontal width of the available display area. All fill-mode columns in the control divide the available space in proportions determined by their System.Windows.Forms.DataGridViewColumn.FillWeight property values. For more information about column fill mode, see Column Fill Mode in the Windows Forms DataGridView Control. + +The maximum sum of System.Windows.Forms.DataGridViewColumn.FillWeight values for all columns in a System.Windows.Forms.DataGridView control is 65535. + */ + } + } + + public override bool Frozen { + get { return frozen; } + set { frozen = value; } + } + /* When a column is frozen, all the columns to its left (or to its right in right-to-left languages) are frozen as well. The frozen and unfrozen columns form two groups. If column repositioning is enabled by setting the System.Windows.Forms.DataGridView.AllowUserToOrderColumns property to true, the user cannot drag a column from one group to the other. +Example */ + + public DataGridViewColumnHeaderCell HeaderCell { + get { return headerCell; } + set { + if (headerCell != value) { + headerCell = value; + if (DataGridView != null) { + DataGridView.OnColumnHeaderCellChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public string HeaderText { + get { return headerText; } + set { headerText = value; } + } + + public DataGridViewAutoSizeColumnMode InheritedAutoSizeMode { + get { return inheritedAutoSizeMode; } + } + + public override DataGridViewCellStyle InheritedStyle { + get { + if (DataGridView == null) { + return base.DefaultCellStyle; + } + else { + if (base.DefaultCellStyle == null) { + return DataGridView.DefaultCellStyle; + } + else { + DataGridViewCellStyle style = (DataGridViewCellStyle) base.DefaultCellStyle.Clone(); + /////// Combination with dataGridView.DefaultCellStyle + return style; + } + } + } + } + + public bool IsDataBound { + get { return isDataBound; } + } + + public int MinimumWidth { + get { return minimumWidth; } + set { + if (minimumWidth != value) { + if (value < 2 || value > Int32.MaxValue) { + throw new ArgumentOutOfRangeException("MinimumWidth is out of range"); + } + minimumWidth = value; + if (DataGridView != null) { + DataGridView.OnColumnMinimumWidthChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public string Name { + get { return name; } + set { + if (name != value) { + name = value; + headerCell.Value = value; + if (DataGridView != null) { + DataGridView.OnColumnNameChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public override bool ReadOnly { + get { return readOnly; } + set { readOnly = value; } + } + + public override DataGridViewTriState Resizable { + get { return resizable; } + set { resizable = value; } + } + + public virtual ISite Site { + get { return site; } + set { site = value; } + } + + public DataGridViewColumnSortMode SortMode { + get { return sortMode; } + set { + // System.InvalidOperationException: The value assigned to the property conflicts with System.Windows.Forms.DataGridView.SelectionMode. + if (sortMode != value) { + sortMode = value; + if (DataGridView != null) { + DataGridView.OnColumnSortModeChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public string ToolTipText { + get { return toolTipText; } + set { + if (toolTipText != value) { + toolTipText = value; + if (DataGridView != null) { + DataGridView.OnColumnToolTipTextChanged(new DataGridViewColumnEventArgs(this)); + } + } + } + } + + public Type ValueType { + get { return valueType; } + set { valueType = value; } + } + + public override bool Visible { + get { return visible; } + set { visible = value; } + } + + public int Width { + get { return width; } + set { + if (width != value) { + if (value < minimumWidth) { + throw new ArgumentOutOfRangeException("Width is less than MinimumWidth"); + } + width = value; + if (DataGridView != null) { + DataGridView.OnColumnWidthChanged(new DataGridViewColumnEventArgs(this)); + } + + } + } + } + + //public sealed event EventHandler Disposed; + public event EventHandler Disposed; + + public override object Clone () { + return this.MemberwiseClone(); + /* + DataGridViewColumn result = new DataGridViewColumn(); + return result; + */ + } + + //public sealed void Dispose () { + //} + + public virtual int GetPreferredWidth (DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight) { + switch (autoSizeColumnMode) { + case DataGridViewAutoSizeColumnMode.NotSet: + case DataGridViewAutoSizeColumnMode.None: + case DataGridViewAutoSizeColumnMode.Fill: + throw new ArgumentException("AutoSizeColumnMode is invalid"); + } + if (fixedHeight) { + return 0; + } + else { + return 0; + } + } + + public override string ToString () { + return Name + ", Index: " + base.Index.ToString() + "."; + } + + protected override void Dispose (bool disposing) { + if (disposing) { + } + } + + internal override void SetDataGridView (DataGridView dataGridView) { + base.SetDataGridView(dataGridView); + if (cellTemplate != null) { + cellTemplate.SetDataGridView(dataGridView); + } + headerCell.SetDataGridView(dataGridView); + } + + internal override void SetIndex (int index) { + base.SetIndex(index); + headerCell.SetColumnIndex(Index); + } + + internal override void SetState (DataGridViewElementStates state) { + if (State != state) { + base.SetState(state); + if (DataGridView != null) { + DataGridView.OnColumnStateChanged(new DataGridViewColumnStateChangedEventArgs(this, state)); + } + } + } + + } + +} + +#endif |