Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / DataGridTable.cs / 1305376 / DataGridTable.cs
//// Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ namespace System.Windows.Forms { using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Text; using System.Collections; using System.Windows.Forms; using System.Windows.Forms.ComponentModel; using System.Drawing; using System.Runtime.InteropServices; using Microsoft.Win32; ////// /// [ ToolboxItem(false), DesignTimeVisible(false), //DefaultProperty("GridTableName") ] public class DataGridTableStyle : Component, IDataGridEditingService { // internal for DataGridColumn accessibility... // internal DataGrid dataGrid = null; // relationship UI private int relationshipHeight = 0; internal const int relationshipSpacing = 1; private Rectangle relationshipRect = Rectangle.Empty; private int focusedRelation = -1; private int focusedTextWidth; // will contain a list of relationships that this table has private ArrayList relationsList = new ArrayList(2); // the name of the table private string mappingName = ""; private GridColumnStylesCollection gridColumns = null; private bool readOnly = false; private bool isDefaultTableStyle = false; private static readonly object EventAllowSorting = new object(); private static readonly object EventGridLineColor = new object(); private static readonly object EventGridLineStyle = new object(); private static readonly object EventHeaderBackColor = new object(); private static readonly object EventHeaderForeColor = new object(); private static readonly object EventHeaderFont = new object(); private static readonly object EventLinkColor = new object(); private static readonly object EventLinkHoverColor = new object(); private static readonly object EventPreferredColumnWidth = new object(); private static readonly object EventPreferredRowHeight = new object(); private static readonly object EventColumnHeadersVisible = new object(); private static readonly object EventRowHeaderWidth = new object(); private static readonly object EventSelectionBackColor = new object(); private static readonly object EventSelectionForeColor = new object(); private static readonly object EventMappingName = new object(); private static readonly object EventAlternatingBackColor = new object(); private static readonly object EventBackColor = new object(); private static readonly object EventForeColor = new object(); private static readonly object EventReadOnly = new object(); private static readonly object EventRowHeadersVisible = new object(); // add a bunch of properties, taken from the dataGrid // // default values // private const bool defaultAllowSorting = true; private const DataGridLineStyle defaultGridLineStyle = DataGridLineStyle.Solid; private const int defaultPreferredColumnWidth = 75; private const int defaultRowHeaderWidth = 35; internal static readonly Font defaultFont = Control.DefaultFont; internal static readonly int defaultFontHeight = defaultFont.Height; // the actual place holders for properties // private bool allowSorting = defaultAllowSorting; private SolidBrush alternatingBackBrush = DefaultAlternatingBackBrush; private SolidBrush backBrush = DefaultBackBrush; private SolidBrush foreBrush = DefaultForeBrush; private SolidBrush gridLineBrush = DefaultGridLineBrush; private DataGridLineStyle gridLineStyle = defaultGridLineStyle; internal SolidBrush headerBackBrush = DefaultHeaderBackBrush; internal Font headerFont = null; // this is ambient property to Font value. internal SolidBrush headerForeBrush = DefaultHeaderForeBrush; internal Pen headerForePen = DefaultHeaderForePen; private SolidBrush linkBrush = DefaultLinkBrush; internal int preferredColumnWidth = defaultPreferredColumnWidth; private int prefferedRowHeight = defaultFontHeight + 3; private SolidBrush selectionBackBrush = DefaultSelectionBackBrush; private SolidBrush selectionForeBrush = DefaultSelectionForeBrush; private int rowHeaderWidth = defaultRowHeaderWidth; private bool rowHeadersVisible = true; private bool columnHeadersVisible = true; // the dataGrid would need to know when the ColumnHeaderVisible, RowHeadersVisible, RowHeaderWidth // and preferredColumnWidth, preferredRowHeight properties are changed in the current dataGridTableStyle // also: for GridLineStyle, GridLineColor, ForeColor, BackColor, HeaderBackColor, HeaderFont, HeaderForeColor // LinkColor, LinkHoverColor // ///Represents the table drawn by the ///control at run time. /// /// [ SRCategory(SR.CatBehavior), DefaultValue(defaultAllowSorting), SRDescription(SR.DataGridAllowSortingDescr) ] public bool AllowSorting { get { return allowSorting; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "AllowSorting")); } if (allowSorting != value) { allowSorting = value; OnAllowSortingChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler AllowSortingChanged { add { Events.AddHandler(EventAllowSorting, value); } remove { Events.RemoveHandler(EventAllowSorting, value); } } ///[To be supplied] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.DataGridAlternatingBackColorDescr) ] public Color AlternatingBackColor { get { return alternatingBackBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "AlternatingBackColor")); } if (System.Windows.Forms.DataGrid.IsTransparentColor(value)) throw new ArgumentException(SR.GetString(SR.DataGridTableStyleTransparentAlternatingBackColorNotAllowed)); if (value.IsEmpty) { throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "AlternatingBackColor")); } if (!alternatingBackBrush.Color.Equals(value)) { alternatingBackBrush = new SolidBrush(value); InvalidateInside(); OnAlternatingBackColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler AlternatingBackColorChanged { add { Events.AddHandler(EventAlternatingBackColor, value); } remove { Events.RemoveHandler(EventAlternatingBackColor, value); } } ///[To be supplied.] ////// /// public void ResetAlternatingBackColor() { if (ShouldSerializeAlternatingBackColor()) { AlternatingBackColor = DefaultAlternatingBackBrush.Color; InvalidateInside(); } } ///[To be supplied.] ////// /// protected virtual bool ShouldSerializeAlternatingBackColor() { return !AlternatingBackBrush.Equals(DefaultAlternatingBackBrush); } internal SolidBrush AlternatingBackBrush { get { return alternatingBackBrush; } } ///[To be supplied.] ////// /// protected bool ShouldSerializeBackColor() { return !System.Windows.Forms.DataGridTableStyle.DefaultBackBrush.Equals(this.backBrush); } ///[To be supplied.] ////// /// protected bool ShouldSerializeForeColor() { return !System.Windows.Forms.DataGridTableStyle.DefaultForeBrush.Equals(this.foreBrush); } internal SolidBrush BackBrush { get { return this.backBrush; } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.ControlBackColorDescr) ] public Color BackColor { get { return this.backBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "BackColor")); } if (System.Windows.Forms.DataGrid.IsTransparentColor(value)) throw new ArgumentException(SR.GetString(SR.DataGridTableStyleTransparentBackColorNotAllowed)); if (value.IsEmpty) { throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "BackColor")); } if (!backBrush.Color.Equals(value)) { this.backBrush = new SolidBrush(value); InvalidateInside(); OnBackColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler BackColorChanged { add { Events.AddHandler(EventBackColor, value); } remove { Events.RemoveHandler(EventBackColor, value); } } ///[To be supplied.] ////// /// public void ResetBackColor() { if (!this.backBrush.Equals(DefaultBackBrush)) { this.BackColor = DefaultBackBrush.Color; } } internal int BorderWidth { get { DataGrid dataGrid = this.DataGrid; if (dataGrid == null) return 0; // if the user set the GridLineStyle property on the dataGrid. // then use the value of that property DataGridLineStyle gridStyle; int gridLineWidth; if (this.IsDefault) { gridStyle = this.DataGrid.GridLineStyle; gridLineWidth = this.DataGrid.GridLineWidth; } else { gridStyle = this.GridLineStyle; gridLineWidth = this.GridLineWidth; } if (gridStyle == DataGridLineStyle.None) return 0; return gridLineWidth; } } internal static SolidBrush DefaultAlternatingBackBrush { get { return (SolidBrush)SystemBrushes.Window; } } internal static SolidBrush DefaultBackBrush { get { return (SolidBrush)SystemBrushes.Window; } } internal static SolidBrush DefaultForeBrush { get { return (SolidBrush)SystemBrushes.WindowText; } } private static SolidBrush DefaultGridLineBrush { get { return (SolidBrush)SystemBrushes.Control; } } private static SolidBrush DefaultHeaderBackBrush { get { return (SolidBrush)SystemBrushes.Control; } } private static SolidBrush DefaultHeaderForeBrush { get { return (SolidBrush)SystemBrushes.ControlText; } } private static Pen DefaultHeaderForePen { get { return new Pen(SystemColors.ControlText); } } private static SolidBrush DefaultLinkBrush { get { return (SolidBrush)SystemBrushes.HotTrack; } } private static SolidBrush DefaultSelectionBackBrush { get { return (SolidBrush)SystemBrushes.ActiveCaption; } } private static SolidBrush DefaultSelectionForeBrush { get { return (SolidBrush)SystemBrushes.ActiveCaptionText; } } internal int FocusedRelation { get { return focusedRelation; } set { if (focusedRelation != value) { focusedRelation = value; if (focusedRelation == -1) { focusedTextWidth = 0; } else { Graphics g = DataGrid.CreateGraphicsInternal(); focusedTextWidth = (int) Math.Ceiling(g.MeasureString(((string) RelationsList[focusedRelation]), DataGrid.LinkFont).Width); g.Dispose(); } } } } internal int FocusedTextWidth { get { return this.focusedTextWidth; } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.ControlForeColorDescr) ] public Color ForeColor { get { return this.foreBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "ForeColor")); } if (value.IsEmpty) { throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "BackColor")); } if (!foreBrush.Color.Equals(value)) { this.foreBrush = new SolidBrush(value); InvalidateInside(); OnForeColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler ForeColorChanged { add { Events.AddHandler(EventForeColor, value); } remove { Events.RemoveHandler(EventForeColor, value); } } internal SolidBrush ForeBrush { get { return this.foreBrush; } } ///[To be supplied.] ////// /// public void ResetForeColor() { if (!this.foreBrush.Equals(DefaultForeBrush)) { this.ForeColor = DefaultForeBrush.Color; } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.DataGridGridLineColorDescr) ] public Color GridLineColor { get { return gridLineBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "GridLineColor")); } if (gridLineBrush.Color != value) { if (value.IsEmpty) throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "GridLineColor")); gridLineBrush = new SolidBrush(value); // Invalidate(layout.Data); OnGridLineColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler GridLineColorChanged { add { Events.AddHandler(EventGridLineColor, value); } remove { Events.RemoveHandler(EventGridLineColor, value); } } ///[To be supplied.] ////// /// protected virtual bool ShouldSerializeGridLineColor() { return !GridLineBrush.Equals(DefaultGridLineBrush); } ///[To be supplied.] ////// /// public void ResetGridLineColor() { if (ShouldSerializeGridLineColor()) { GridLineColor = DefaultGridLineBrush.Color; } } internal SolidBrush GridLineBrush { get { return gridLineBrush; } } internal int GridLineWidth { get { Debug.Assert(this.GridLineStyle == DataGridLineStyle.Solid || this.GridLineStyle == DataGridLineStyle.None, "are there any other styles?"); return GridLineStyle == DataGridLineStyle.Solid ? 1 : 0; } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatAppearance), DefaultValue(defaultGridLineStyle), SRDescription(SR.DataGridGridLineStyleDescr) ] public DataGridLineStyle GridLineStyle { get { return gridLineStyle; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "GridLineStyle")); } //valid values are 0x0 to 0x1. if (!ClientUtils.IsEnumValid(value, (int)value, (int)DataGridLineStyle.None, (int)DataGridLineStyle.Solid)) { throw new InvalidEnumArgumentException("value", (int)value, typeof(DataGridLineStyle)); } if (gridLineStyle != value) { gridLineStyle = value; // Invalidate(layout.Data); OnGridLineStyleChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler GridLineStyleChanged { add { Events.AddHandler(EventGridLineStyle, value); } remove { Events.RemoveHandler(EventGridLineStyle, value); } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.DataGridHeaderBackColorDescr) ] public Color HeaderBackColor { get { return headerBackBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "HeaderBackColor")); } if (System.Windows.Forms.DataGrid.IsTransparentColor(value)) throw new ArgumentException(SR.GetString(SR.DataGridTableStyleTransparentHeaderBackColorNotAllowed)); if (value.IsEmpty) throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "HeaderBackColor")); if (!value.Equals(headerBackBrush.Color)) { headerBackBrush = new SolidBrush(value); /* if (layout.RowHeadersVisible) Invalidate(layout.RowHeaders); if (layout.ColumnHeadersVisible) Invalidate(layout.ColumnHeaders); Invalidate(layout.TopLeftHeader); */ OnHeaderBackColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler HeaderBackColorChanged { add { Events.AddHandler(EventHeaderBackColor, value); } remove { Events.RemoveHandler(EventHeaderBackColor, value); } } internal SolidBrush HeaderBackBrush { get { return headerBackBrush; } } ///[To be supplied.] ////// /// protected virtual bool ShouldSerializeHeaderBackColor() { return !HeaderBackBrush.Equals(DefaultHeaderBackBrush); } ///[To be supplied.] ////// /// public void ResetHeaderBackColor() { if(ShouldSerializeHeaderBackColor()) { HeaderBackColor = DefaultHeaderBackBrush.Color; } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatAppearance), Localizable(true), AmbientValue(null), SRDescription(SR.DataGridHeaderFontDescr) ] public Font HeaderFont { get { return(headerFont == null ? (this.DataGrid == null ? Control.DefaultFont : this.DataGrid.Font) : headerFont); } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "HeaderFont")); } if (value == null && headerFont != null || (value != null && !value.Equals(headerFont))) { headerFont = value; /* RecalculateFonts(); PerformLayout(); Invalidate(layout.Inside); */ OnHeaderFontChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler HeaderFontChanged { add { Events.AddHandler(EventHeaderFont, value); } remove { Events.RemoveHandler(EventHeaderFont, value); } } ///[To be supplied.] ////// /// private bool ShouldSerializeHeaderFont() { return(headerFont != null); } ///[To be supplied.] ////// /// public void ResetHeaderFont() { if (headerFont != null) { headerFont = null; /* RecalculateFonts(); PerformLayout(); Invalidate(layout.Inside); */ OnHeaderFontChanged(EventArgs.Empty); } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.DataGridHeaderForeColorDescr) ] public Color HeaderForeColor { get { return headerForePen.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "HeaderForeColor")); } if (value.IsEmpty) throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "HeaderForeColor")); if (!value.Equals(headerForePen.Color)) { headerForePen = new Pen(value); headerForeBrush = new SolidBrush(value); /* if (layout.RowHeadersVisible) Invalidate(layout.RowHeaders); if (layout.ColumnHeadersVisible) Invalidate(layout.ColumnHeaders); Invalidate(layout.TopLeftHeader); */ OnHeaderForeColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ///public event EventHandler HeaderForeColorChanged { add { Events.AddHandler(EventHeaderForeColor, value); } remove { Events.RemoveHandler(EventHeaderForeColor, value); } } /// /// /// protected virtual bool ShouldSerializeHeaderForeColor() { return !HeaderForePen.Equals(DefaultHeaderForePen); } ///[To be supplied.] ////// /// public void ResetHeaderForeColor() { if(ShouldSerializeHeaderForeColor()) { HeaderForeColor = DefaultHeaderForeBrush.Color; } } internal SolidBrush HeaderForeBrush { get { return this.headerForeBrush; } } internal Pen HeaderForePen { get { return headerForePen; } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.DataGridLinkColorDescr) ] public Color LinkColor { get { return linkBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "LinkColor")); } if (value.IsEmpty) throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "LinkColor")); if (!linkBrush.Color.Equals(value)) { linkBrush = new SolidBrush(value); // Invalidate(layout.Data); OnLinkColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler LinkColorChanged { add { Events.AddHandler(EventLinkColor, value); } remove { Events.RemoveHandler(EventLinkColor, value); } } ///[To be supplied.] ////// /// protected virtual bool ShouldSerializeLinkColor() { return !LinkBrush.Equals(DefaultLinkBrush); } ///[To be supplied.] ////// /// public void ResetLinkColor() { if (ShouldSerializeLinkColor()) LinkColor = DefaultLinkBrush.Color; } internal Brush LinkBrush { get { return linkBrush; } } ///[To be supplied.] ////// /// /// [ SRDescription(SR.DataGridLinkHoverColorDescr), SRCategory(SR.CatColors), Browsable(false), EditorBrowsable(EditorBrowsableState.Never) ] public Color LinkHoverColor { get { return this.LinkColor; } [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters")] set { } } ///[To be supplied.] ////// /// /// public event EventHandler LinkHoverColorChanged { add { Events.AddHandler(EventLinkHoverColor, value); } remove { Events.RemoveHandler(EventLinkHoverColor, value); } } ///[To be supplied.] ////// /// /// protected virtual bool ShouldSerializeLinkHoverColor() { return false; // return !LinkHoverBrush.Equals(defaultLinkHoverBrush); } internal Rectangle RelationshipRect { get { if (this.relationshipRect.IsEmpty) { ComputeRelationshipRect(); } return this.relationshipRect; } } private Rectangle ComputeRelationshipRect() { if (relationshipRect.IsEmpty && DataGrid.AllowNavigation) { Debug.WriteLineIf(CompModSwitches.DGRelationShpRowLayout.TraceVerbose, "GetRelationshipRect grinding away"); Graphics g = DataGrid.CreateGraphicsInternal(); relationshipRect = new Rectangle(); relationshipRect.X = 0; //indentWidth; // relationshipRect.Y = base.Height - BorderWidth; // Determine the width of the widest relationship name int longestRelationship = 0; for (int r = 0; r < this.RelationsList.Count; ++r) { int rwidth = (int) Math.Ceiling(g.MeasureString(((string) this.RelationsList[r]), this.DataGrid.LinkFont).Width) ; if (rwidth > longestRelationship) longestRelationship = rwidth; } g.Dispose(); relationshipRect.Width = longestRelationship + 5; relationshipRect.Width += 2; // relationshipRect border; relationshipRect.Height = BorderWidth + relationshipHeight * this.RelationsList.Count; relationshipRect.Height += 2; // relationship border if (this.RelationsList.Count > 0) relationshipRect.Height += 2 * relationshipSpacing; } return relationshipRect; } internal void ResetRelationsUI() { this.relationshipRect = Rectangle.Empty; this.focusedRelation = -1; this.relationshipHeight = this.dataGrid.LinkFontHeight + relationshipSpacing; } internal int RelationshipHeight { get { return this.relationshipHeight; } } ///[To be supplied.] ////// /// /// public void ResetLinkHoverColor() { /*if (ShouldSerializeLinkHoverColor()) LinkHoverColor = defaultLinkHoverBrush.Color;*/ } ///[To be supplied.] ////// /// [ DefaultValue(defaultPreferredColumnWidth), SRCategory(SR.CatLayout), Localizable(true), SRDescription(SR.DataGridPreferredColumnWidthDescr), TypeConverter(typeof(DataGridPreferredColumnWidthTypeConverter)) ] public int PreferredColumnWidth { get { return preferredColumnWidth; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "PreferredColumnWidth")); } if (value < 0) throw new ArgumentException(SR.GetString(SR.DataGridColumnWidth), "PreferredColumnWidth"); if (preferredColumnWidth != value) { preferredColumnWidth = value; /* // reset the dataGridRows SetDataGridRows(null, this.DataGridRowsLength); // layout the horizontal scroll bar PerformLayout(); // invalidate everything Invalidate(); */ OnPreferredColumnWidthChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler PreferredColumnWidthChanged { add { Events.AddHandler(EventPreferredColumnWidth, value); } remove { Events.RemoveHandler(EventPreferredColumnWidth, value); } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatLayout), Localizable(true), SRDescription(SR.DataGridPreferredRowHeightDescr) ] public int PreferredRowHeight { get { return prefferedRowHeight; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "PrefferedRowHeight")); } if (value < 0) throw new ArgumentException(SR.GetString(SR.DataGridRowRowHeight)); prefferedRowHeight = value; /* bool needToRedraw = false; DataGridRow[] rows = DataGridRows; for (int i = 0; i < DataGridRowsLength; i++) { if (rows[i].Height != value) needToRedraw = false; rows[i].Height = value; } // if all rows' height was equal to "value" before setting it, then // there is no need to redraw. if (!needToRedraw) return; // need to layout the scroll bars: PerformLayout(); // invalidate the entire area... Rectangle rightArea = Rectangle.Union(layout.RowHeaders, layout.Data); Invalidate(rightArea); */ OnPreferredRowHeightChanged(EventArgs.Empty); } } ///[To be supplied.] ////// /// public event EventHandler PreferredRowHeightChanged { add { Events.AddHandler(EventPreferredRowHeight, value); } remove { Events.RemoveHandler(EventPreferredRowHeight, value); } } private void ResetPreferredRowHeight() { PreferredRowHeight = defaultFontHeight + 3; } ///[To be supplied.] ////// /// protected bool ShouldSerializePreferredRowHeight() { return prefferedRowHeight != defaultFontHeight + 3; } ///[To be supplied.] ////// /// [ SRCategory(SR.CatDisplay), DefaultValue(true), SRDescription(SR.DataGridColumnHeadersVisibleDescr) ] public bool ColumnHeadersVisible { get { return columnHeadersVisible; } set { if (columnHeadersVisible != value) { columnHeadersVisible = value; /* PerformLayout(); InvalidateInside(); */ OnColumnHeadersVisibleChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler ColumnHeadersVisibleChanged { add { Events.AddHandler(EventColumnHeadersVisible, value); } remove { Events.RemoveHandler(EventColumnHeadersVisible, value); } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatDisplay), DefaultValue(true), SRDescription(SR.DataGridRowHeadersVisibleDescr) ] public bool RowHeadersVisible { get { return rowHeadersVisible; } set { if (rowHeadersVisible != value) { rowHeadersVisible = value; /* PerformLayout(); InvalidateInside(); */ OnRowHeadersVisibleChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler RowHeadersVisibleChanged { add { Events.AddHandler(EventRowHeadersVisible, value); } remove { Events.RemoveHandler(EventRowHeadersVisible, value); } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatLayout), DefaultValue(defaultRowHeaderWidth), Localizable(true), SRDescription(SR.DataGridRowHeaderWidthDescr) ] public int RowHeaderWidth { get { return rowHeaderWidth; } set { if (this.DataGrid != null) value = Math.Max(this.DataGrid.MinimumRowHeaderWidth(), value); if (rowHeaderWidth != value) { rowHeaderWidth = value; /* if (layout.RowHeadersVisible) { PerformLayout(); InvalidateInside(); } */ OnRowHeaderWidthChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler RowHeaderWidthChanged { add { Events.AddHandler(EventRowHeaderWidth, value); } remove { Events.RemoveHandler(EventRowHeaderWidth, value); } } ///[To be supplied.] ////// /// [ SRCategory(SR.CatColors), SRDescription(SR.DataGridSelectionBackColorDescr) ] public Color SelectionBackColor { get { return selectionBackBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "SelectionBackColor")); } if (System.Windows.Forms.DataGrid.IsTransparentColor(value)) throw new ArgumentException(SR.GetString(SR.DataGridTableStyleTransparentSelectionBackColorNotAllowed)); if (value.IsEmpty) throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "SelectionBackColor")); if (!value.Equals(selectionBackBrush.Color)) { selectionBackBrush = new SolidBrush(value); InvalidateInside(); OnSelectionBackColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler SelectionBackColorChanged { add { Events.AddHandler(EventSelectionBackColor, value); } remove { Events.RemoveHandler(EventSelectionBackColor, value); } } internal SolidBrush SelectionBackBrush { get { return this.selectionBackBrush; } } internal SolidBrush SelectionForeBrush { get { return this.selectionForeBrush; } } ///[To be supplied.] ////// /// protected bool ShouldSerializeSelectionBackColor() { return !DefaultSelectionBackBrush.Equals(selectionBackBrush); } ///[To be supplied.] ////// /// public void ResetSelectionBackColor() { if (ShouldSerializeSelectionBackColor()) SelectionBackColor = DefaultSelectionBackBrush.Color; } ///[To be supplied.] ////// /// [ Description("The foreground color for the current data grid row"), SRCategory(SR.CatColors), SRDescription(SR.DataGridSelectionForeColorDescr) ] public Color SelectionForeColor { get { return selectionForeBrush.Color; } set { if (this.isDefaultTableStyle) { throw new ArgumentException(SR.GetString(SR.DataGridDefaultTableSet, "SelectionForeColor")); } if (value.IsEmpty) throw new ArgumentException(SR.GetString(SR.DataGridEmptyColor, "SelectionForeColor")); if (!value.Equals(selectionForeBrush.Color)) { selectionForeBrush = new SolidBrush(value); InvalidateInside(); OnSelectionForeColorChanged(EventArgs.Empty); } } } ///[To be supplied.] ////// /// public event EventHandler SelectionForeColorChanged { add { Events.AddHandler(EventSelectionForeColor, value); } remove { Events.RemoveHandler(EventSelectionForeColor, value); } } ///[To be supplied.] ////// /// protected virtual bool ShouldSerializeSelectionForeColor() { return !SelectionForeBrush.Equals(DefaultSelectionForeBrush); } ///[To be supplied.] ////// /// public void ResetSelectionForeColor() { if (ShouldSerializeSelectionForeColor()) SelectionForeColor = DefaultSelectionForeBrush.Color; } // will need this function from the dataGrid // private void InvalidateInside() { if (this.DataGrid != null) this.DataGrid.InvalidateInside(); } ///[To be supplied.] ////// /// /// [ SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes") // This has already shipped so we can't change it. ] public static readonly DataGridTableStyle DefaultTableStyle = new DataGridTableStyle(true); ///[To be supplied.] ////// /// /// public DataGridTableStyle(bool isDefaultTableStyle) { gridColumns = new GridColumnStylesCollection(this, isDefaultTableStyle); gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged); this.isDefaultTableStyle = isDefaultTableStyle; } ///Initializes a new instance of the ///class. /// /// public DataGridTableStyle() : this(false) { } ///[To be supplied.] ////// /// [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // If the constructor does not set the GridColumnStyles // it would be a breaking change. ] public DataGridTableStyle(CurrencyManager listManager) : this() { Debug.Assert(listManager != null, "the DataGridTabel cannot use a null listManager"); this.mappingName = listManager.GetListName(); // set up the Relations and the columns SetGridColumnStylesCollection(listManager); } internal void SetRelationsList(CurrencyManager listManager) { PropertyDescriptorCollection propCollection = listManager.GetItemProperties(); Debug.Assert(!this.IsDefault, "the grid can set the relations only on a table that was manually added by the user"); int propCount = propCollection.Count; if (relationsList.Count > 0) relationsList.Clear(); for (int i = 0; i < propCount; i++) { PropertyDescriptor prop = propCollection[i]; Debug.Assert(prop != null, "prop is null: how that happened?"); if (PropertyDescriptorIsARelation(prop)) { // relation relationsList.Add(prop.Name); } } } internal void SetGridColumnStylesCollection(CurrencyManager listManager) { // when we are setting the gridColumnStyles, do not handle any gridColumnCollectionChanged events gridColumns.CollectionChanged -= new CollectionChangeEventHandler(this.OnColumnCollectionChanged); PropertyDescriptorCollection propCollection = listManager.GetItemProperties(); // we need to clear the relations list if (relationsList.Count > 0) relationsList.Clear(); Debug.Assert(propCollection != null, "propCollection is null: how that happened?"); int propCount = propCollection.Count; for (int i = 0; i < propCount; i++) { PropertyDescriptor prop = propCollection[i]; Debug.Assert(prop != null, "prop is null: how that happened?"); // do not take into account the properties that are browsable. if (!prop.IsBrowsable) continue; if (PropertyDescriptorIsARelation(prop)) { // relation relationsList.Add(prop.Name); } else { // column DataGridColumnStyle col = this.CreateGridColumn(prop, this.isDefaultTableStyle); if (this.isDefaultTableStyle) gridColumns.AddDefaultColumn(col); else { col.MappingName = prop.Name; col.HeaderText = prop.Name; gridColumns.Add(col); } } } // now we are able to handle the collectionChangeEvents gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged); } private static bool PropertyDescriptorIsARelation(PropertyDescriptor prop) { return typeof(IList).IsAssignableFrom(prop.PropertyType) && !typeof(Array).IsAssignableFrom(prop.PropertyType); } ///Initializes a new instance of the ///class with the specified /// . internal protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop) { return this.CreateGridColumn(prop, false); } /// internal protected virtual DataGridColumnStyle CreateGridColumn(PropertyDescriptor prop, bool isDefault) { DataGridColumnStyle ret = null; Type dataType = prop.PropertyType; if (dataType.Equals(typeof(bool))) ret = new DataGridBoolColumn(prop, isDefault); else if (dataType.Equals(typeof(string))) ret = new DataGridTextBoxColumn(prop, isDefault); else if (dataType.Equals(typeof(DateTime))) ret = new DataGridTextBoxColumn(prop, "d", isDefault); else if (dataType.Equals(typeof(Int16)) || dataType.Equals(typeof(Int32)) || dataType.Equals(typeof(Int64)) || dataType.Equals(typeof(UInt16)) || dataType.Equals(typeof(UInt32)) || dataType.Equals(typeof(UInt64)) || dataType.Equals(typeof(Decimal)) || dataType.Equals(typeof(Double)) || dataType.Equals(typeof(Single)) || dataType.Equals(typeof(Byte)) || dataType.Equals(typeof(SByte))) { ret = new DataGridTextBoxColumn(prop, "G", isDefault); } else { ret = new DataGridTextBoxColumn(prop, isDefault); } return ret; } internal void ResetRelationsList() { if (this.isDefaultTableStyle) { relationsList.Clear(); } } // =----------------------------------------------------------------- // = Properties // =----------------------------------------------------------------- /// /// /// [Editor("System.Windows.Forms.Design.DataGridTableStyleMappingNameEditor, " + AssemblyRef.SystemDesign, typeof(System.Drawing.Design.UITypeEditor)), DefaultValue("")] public string MappingName { get { return mappingName; } set { if (value == null) value = ""; if (value.Equals(mappingName)) return; string originalMappingName = this.MappingName; mappingName = value; // this could throw try { if (this.DataGrid != null) this.DataGrid.TableStyles.CheckForMappingNameDuplicates(this); } catch { this.mappingName = originalMappingName; throw; } OnMappingNameChanged(EventArgs.Empty); } } ///Gets the name of this grid table. ////// /// public event EventHandler MappingNameChanged { add { Events.AddHandler(EventMappingName, value); } remove { Events.RemoveHandler(EventMappingName, value); } } ///[To be supplied.] ////// /// internal ArrayList RelationsList { get { return relationsList; } } ///Gets the /// list of relation objects for the grid table. ////// /// [ Localizable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content) ] public virtual GridColumnStylesCollection GridColumnStyles { get { return gridColumns; } } ///Gets the collection of columns drawn for this table. ////// /// internal void SetInternalDataGrid(DataGrid dG, bool force) { if (dataGrid != null && dataGrid.Equals(dG) && !force) return; else { dataGrid = dG; if (dG != null && dG.Initializing) return; int nCols = gridColumns.Count; for (int i = 0; i < nCols; i++) gridColumns[i].SetDataGridInternalInColumn(dG); } } ////// Gets or sets the ////// control displaying the table. /// /// /// [Browsable(false)] public virtual DataGrid DataGrid { get { return dataGrid; } set { SetInternalDataGrid(value, true); } } ///Gets or sets the ///control for the drawn table. /// /// [DefaultValue(false)] public virtual bool ReadOnly { get { return readOnly; } set { if (readOnly != value) { readOnly = value; OnReadOnlyChanged(EventArgs.Empty); } } } ///Gets or sets a value indicating whether columns can be /// edited. ////// /// public event EventHandler ReadOnlyChanged { add { Events.AddHandler(EventReadOnly, value); } remove { Events.RemoveHandler(EventReadOnly, value); } } // =----------------------------------------------------------------- // = Methods // =------------------------------------------------------------------ ///[To be supplied.] ////// /// public bool BeginEdit(DataGridColumnStyle gridColumn, int rowNumber) { DataGrid grid = this.DataGrid; if (grid == null) return false; else return grid.BeginEdit(gridColumn, rowNumber); } ///Requests an edit operation. ////// /// public bool EndEdit(DataGridColumnStyle gridColumn, int rowNumber, bool shouldAbort) { DataGrid grid = this.DataGrid; if (grid == null) return false; else return grid.EndEdit(gridColumn, rowNumber, shouldAbort); } internal void InvalidateColumn(DataGridColumnStyle column) { int index = GridColumnStyles.IndexOf(column); if (index >= 0 && DataGrid != null) DataGrid.InvalidateColumn(index); } private void OnColumnCollectionChanged(object sender, CollectionChangeEventArgs e) { gridColumns.CollectionChanged -= new CollectionChangeEventHandler(this.OnColumnCollectionChanged); try { DataGrid grid = this.DataGrid; DataGridColumnStyle col = e.Element as DataGridColumnStyle; if (e.Action == CollectionChangeAction.Add) { if (col != null) col.SetDataGridInternalInColumn(grid); } else if (e.Action == CollectionChangeAction.Remove) { if (col != null) col.SetDataGridInternalInColumn(null); } else { // refresh Debug.Assert(e.Action == CollectionChangeAction.Refresh, "there are only Add, Remove and Refresh in the CollectionChangeAction"); // if we get a column in this collectionChangeEventArgs it means // that the propertyDescriptor in that column changed. if (e.Element != null) for (int i = 0; i < gridColumns.Count; i++ ) gridColumns[i].SetDataGridInternalInColumn(null); } if (grid != null) grid.OnColumnCollectionChanged(this, e); } finally { gridColumns.CollectionChanged += new CollectionChangeEventHandler(this.OnColumnCollectionChanged); } } #if false ///Requests an end to an edit /// operation. ////// /// The DataColumnCollection class actually wires up this /// event handler to the PropertyChanged events of /// a DataGridTable's columns. /// internal void OnColumnChanged(object sender, PropertyChangedEvent event) { if (event.PropertyName.Equals("Visible")) GenerateVisibleColumnsCache(); } #endif ////// /// protected virtual void OnReadOnlyChanged(EventArgs e) { EventHandler eh = Events[EventReadOnly] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnMappingNameChanged(EventArgs e) { EventHandler eh = Events[EventMappingName] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ///protected virtual void OnAlternatingBackColorChanged(EventArgs e) { EventHandler eh = Events[EventAlternatingBackColor] as EventHandler; if (eh != null) eh(this, e); } /// protected virtual void OnForeColorChanged(EventArgs e) { EventHandler eh = Events[EventBackColor] as EventHandler; if (eh != null) eh(this, e); } /// protected virtual void OnBackColorChanged(EventArgs e) { EventHandler eh = Events[EventForeColor] as EventHandler; if (eh != null) eh(this, e); } /// /// /// protected virtual void OnAllowSortingChanged(EventArgs e) { EventHandler eh = Events[EventAllowSorting] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnGridLineColorChanged(EventArgs e) { EventHandler eh = Events[EventGridLineColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnGridLineStyleChanged(EventArgs e) { EventHandler eh = Events[EventGridLineStyle] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnHeaderBackColorChanged(EventArgs e) { EventHandler eh = Events[EventHeaderBackColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnHeaderFontChanged(EventArgs e) { EventHandler eh = Events[EventHeaderFont] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnHeaderForeColorChanged(EventArgs e) { EventHandler eh = Events[EventHeaderForeColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnLinkColorChanged(EventArgs e) { EventHandler eh = Events[EventLinkColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnLinkHoverColorChanged(EventArgs e) { EventHandler eh = Events[EventLinkHoverColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnPreferredRowHeightChanged(EventArgs e) { EventHandler eh = Events[EventPreferredRowHeight] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnPreferredColumnWidthChanged(EventArgs e) { EventHandler eh = Events[EventPreferredColumnWidth] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnColumnHeadersVisibleChanged(EventArgs e) { EventHandler eh = Events[EventColumnHeadersVisible] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnRowHeadersVisibleChanged(EventArgs e) { EventHandler eh = Events[EventRowHeadersVisible] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnRowHeaderWidthChanged(EventArgs e) { EventHandler eh = Events[EventRowHeaderWidth] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnSelectionForeColorChanged(EventArgs e) { EventHandler eh = Events[EventSelectionForeColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected virtual void OnSelectionBackColorChanged(EventArgs e) { EventHandler eh = Events[EventSelectionBackColor] as EventHandler; if (eh != null) eh(this, e); } ///[To be supplied.] ////// /// protected override void Dispose(bool disposing) { if (disposing) { GridColumnStylesCollection cols = this.GridColumnStyles; if (cols != null) { for (int i = 0; i < cols.Count; i++) cols[i].Dispose(); } } base.Dispose(disposing); } internal bool IsDefault { get { return this.isDefaultTableStyle; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OrderPreservingPipeliningSpoolingTask.cs
- SetState.cs
- ExpressionBindingsDialog.cs
- KeyValuePairs.cs
- Win32PrintDialog.cs
- MasterPageCodeDomTreeGenerator.cs
- StdValidatorsAndConverters.cs
- DefaultTextStore.cs
- SecurityDescriptor.cs
- ObjectDataSourceEventArgs.cs
- XmlObjectSerializerWriteContext.cs
- WebBrowserNavigatingEventHandler.cs
- OrderByExpression.cs
- TailCallAnalyzer.cs
- VisualStyleInformation.cs
- DataGridViewSelectedColumnCollection.cs
- CrossAppDomainChannel.cs
- RawStylusSystemGestureInputReport.cs
- UserControlBuildProvider.cs
- ToolStripScrollButton.cs
- ZipIOLocalFileDataDescriptor.cs
- ClientConfigurationHost.cs
- XmlSchemaParticle.cs
- TextMetrics.cs
- RecoverInstanceLocksCommand.cs
- HtmlShim.cs
- InvalidProgramException.cs
- SettingsAttributeDictionary.cs
- WorkflowRuntimeServiceElementCollection.cs
- EncryptedKeyIdentifierClause.cs
- DecoderExceptionFallback.cs
- SmiXetterAccessMap.cs
- ComponentDispatcher.cs
- ConstructorBuilder.cs
- WebDisplayNameAttribute.cs
- PackageRelationship.cs
- Automation.cs
- DelegatingTypeDescriptionProvider.cs
- EmptyReadOnlyDictionaryInternal.cs
- TrackingRecord.cs
- SpeechSeg.cs
- ImageClickEventArgs.cs
- UIElementParaClient.cs
- SelectionPattern.cs
- EventLogTraceListener.cs
- ColorMap.cs
- StringStorage.cs
- TableHeaderCell.cs
- TableTextElementCollectionInternal.cs
- ListViewItemMouseHoverEvent.cs
- StateFinalizationDesigner.cs
- DeobfuscatingStream.cs
- TextRange.cs
- BuilderElements.cs
- SqlTypesSchemaImporter.cs
- CalendarSelectionChangedEventArgs.cs
- PrintingPermissionAttribute.cs
- BaseTransportHeaders.cs
- GlyphTypeface.cs
- NamedElement.cs
- ReadOnlyHierarchicalDataSourceView.cs
- WsdlImporterElement.cs
- TextBoxView.cs
- MethodRental.cs
- ScriptResourceDefinition.cs
- DebugHandleTracker.cs
- MexBindingBindingCollectionElement.cs
- login.cs
- BeginEvent.cs
- ContentHostHelper.cs
- TextTreeText.cs
- HtmlImage.cs
- Keywords.cs
- XmlSchemaAnnotated.cs
- XmlMembersMapping.cs
- DataGridColumn.cs
- SocketAddress.cs
- DataGridViewImageCell.cs
- SiteMapProvider.cs
- HttpCapabilitiesSectionHandler.cs
- RegisteredExpandoAttribute.cs
- StructuralCache.cs
- Drawing.cs
- WinFormsComponentEditor.cs
- DataViewManagerListItemTypeDescriptor.cs
- XmlMtomReader.cs
- SafeNativeMethods.cs
- PagerSettings.cs
- OpCopier.cs
- UserControl.cs
- FilteredDataSetHelper.cs
- Misc.cs
- PropertyTab.cs
- TextAutomationPeer.cs
- DataGridViewComboBoxColumn.cs
- XPathDescendantIterator.cs
- CommandLibraryHelper.cs
- InstanceData.cs
- NativeCppClassAttribute.cs
- OutOfMemoryException.cs