Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / DataGridViewButtonColumn.cs / 1 / DataGridViewButtonColumn.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.Text; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Diagnostics.CodeAnalysis; ///[ToolboxBitmapAttribute(typeof(DataGridViewButtonColumn), "DataGridViewButtonColumn.bmp")] public class DataGridViewButtonColumn : DataGridViewColumn { private static Type columnType = typeof(DataGridViewButtonColumn); private string text; /// [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // Can't think of a workaround. ] public DataGridViewButtonColumn() : base(new DataGridViewButtonCell()) { DataGridViewCellStyle defaultCellStyle = new DataGridViewCellStyle(); defaultCellStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleCenter; this.DefaultCellStyle = defaultCellStyle; } /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public override DataGridViewCell CellTemplate { get { return base.CellTemplate; } set { if (value != null && !(value is System.Windows.Forms.DataGridViewButtonCell)) { throw new InvalidCastException(SR.GetString(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewButtonCell")); } base.CellTemplate = value; } } /// [ Browsable(true), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ColumnDefaultCellStyleDescr) ] public override DataGridViewCellStyle DefaultCellStyle { get { return base.DefaultCellStyle; } set { base.DefaultCellStyle = value; } } /// [ DefaultValue(FlatStyle.Standard), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ButtonColumnFlatStyleDescr) ] public FlatStyle FlatStyle { get { if (this.CellTemplate == null) { throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired)); } return ((DataGridViewButtonCell) this.CellTemplate).FlatStyle; } set { if (this.FlatStyle != value) { ((DataGridViewButtonCell)this.CellTemplate).FlatStyle = value; if (this.DataGridView != null) { DataGridViewRowCollection dataGridViewRows = this.DataGridView.Rows; int rowCount = dataGridViewRows.Count; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex); DataGridViewButtonCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewButtonCell; if (dataGridViewCell != null) { dataGridViewCell.FlatStyleInternal = value; } } this.DataGridView.OnColumnCommonChange(this.Index); } } } } /// [ DefaultValue(null), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ButtonColumnTextDescr) ] public string Text { get { return this.text; } set { if (!string.Equals(value, this.text, StringComparison.Ordinal)) { this.text = value; if (this.DataGridView != null) { if (this.UseColumnTextForButtonValue) { this.DataGridView.OnColumnCommonChange(this.Index); } else { DataGridViewRowCollection dataGridViewRows = this.DataGridView.Rows; int rowCount = dataGridViewRows.Count; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex); DataGridViewButtonCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewButtonCell; if (dataGridViewCell != null && dataGridViewCell.UseColumnTextForButtonValue) { this.DataGridView.OnColumnCommonChange(this.Index); return; } } this.DataGridView.InvalidateColumn(this.Index); } } } } } /// [ DefaultValue(false), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ButtonColumnUseColumnTextForButtonValueDescr) ] public bool UseColumnTextForButtonValue { get { if (this.CellTemplate == null) { throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired)); } return ((DataGridViewButtonCell)this.CellTemplate).UseColumnTextForButtonValue; } set { if (this.UseColumnTextForButtonValue != value) { ((DataGridViewButtonCell)this.CellTemplate).UseColumnTextForButtonValueInternal = value; if (this.DataGridView != null) { DataGridViewRowCollection dataGridViewRows = this.DataGridView.Rows; int rowCount = dataGridViewRows.Count; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex); DataGridViewButtonCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewButtonCell; if (dataGridViewCell != null) { dataGridViewCell.UseColumnTextForButtonValueInternal = value; } } this.DataGridView.OnColumnCommonChange(this.Index); } } } } /// public override object Clone() { DataGridViewButtonColumn dataGridViewColumn; Type thisType = this.GetType(); if (thisType == columnType) //performance improvement { dataGridViewColumn = new DataGridViewButtonColumn(); } else { // SECREVIEW : Late-binding does not represent a security thread, see bug#411899 for more info.. // dataGridViewColumn = (DataGridViewButtonColumn) System.Activator.CreateInstance(thisType); } if (dataGridViewColumn != null) { base.CloneInternal(dataGridViewColumn); dataGridViewColumn.Text = this.text; } return dataGridViewColumn; } private bool ShouldSerializeDefaultCellStyle() { if (!this.HasDefaultCellStyle) { return false; } DataGridViewCellStyle defaultCellStyle = this.DefaultCellStyle; return (!defaultCellStyle.BackColor.IsEmpty || !defaultCellStyle.ForeColor.IsEmpty || !defaultCellStyle.SelectionBackColor.IsEmpty || !defaultCellStyle.SelectionForeColor.IsEmpty || defaultCellStyle.Font != null || !defaultCellStyle.IsNullValueDefault || !defaultCellStyle.IsDataSourceNullValueDefault || !String.IsNullOrEmpty(defaultCellStyle.Format) || !defaultCellStyle.FormatProvider.Equals(System.Globalization.CultureInfo.CurrentCulture) || defaultCellStyle.Alignment != DataGridViewContentAlignment.MiddleCenter || defaultCellStyle.WrapMode != DataGridViewTriState.NotSet || defaultCellStyle.Tag != null || !defaultCellStyle.Padding.Equals(Padding.Empty)); } /// public override string ToString() { StringBuilder sb = new StringBuilder(64); sb.Append("DataGridViewButtonColumn { Name="); sb.Append(this.Name); sb.Append(", Index="); sb.Append(this.Index.ToString(CultureInfo.CurrentCulture)); sb.Append(" }"); return sb.ToString(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using System.Text; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Diagnostics.CodeAnalysis; ///[ToolboxBitmapAttribute(typeof(DataGridViewButtonColumn), "DataGridViewButtonColumn.bmp")] public class DataGridViewButtonColumn : DataGridViewColumn { private static Type columnType = typeof(DataGridViewButtonColumn); private string text; /// [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // Can't think of a workaround. ] public DataGridViewButtonColumn() : base(new DataGridViewButtonCell()) { DataGridViewCellStyle defaultCellStyle = new DataGridViewCellStyle(); defaultCellStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleCenter; this.DefaultCellStyle = defaultCellStyle; } /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public override DataGridViewCell CellTemplate { get { return base.CellTemplate; } set { if (value != null && !(value is System.Windows.Forms.DataGridViewButtonCell)) { throw new InvalidCastException(SR.GetString(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewButtonCell")); } base.CellTemplate = value; } } /// [ Browsable(true), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ColumnDefaultCellStyleDescr) ] public override DataGridViewCellStyle DefaultCellStyle { get { return base.DefaultCellStyle; } set { base.DefaultCellStyle = value; } } /// [ DefaultValue(FlatStyle.Standard), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ButtonColumnFlatStyleDescr) ] public FlatStyle FlatStyle { get { if (this.CellTemplate == null) { throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired)); } return ((DataGridViewButtonCell) this.CellTemplate).FlatStyle; } set { if (this.FlatStyle != value) { ((DataGridViewButtonCell)this.CellTemplate).FlatStyle = value; if (this.DataGridView != null) { DataGridViewRowCollection dataGridViewRows = this.DataGridView.Rows; int rowCount = dataGridViewRows.Count; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex); DataGridViewButtonCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewButtonCell; if (dataGridViewCell != null) { dataGridViewCell.FlatStyleInternal = value; } } this.DataGridView.OnColumnCommonChange(this.Index); } } } } /// [ DefaultValue(null), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ButtonColumnTextDescr) ] public string Text { get { return this.text; } set { if (!string.Equals(value, this.text, StringComparison.Ordinal)) { this.text = value; if (this.DataGridView != null) { if (this.UseColumnTextForButtonValue) { this.DataGridView.OnColumnCommonChange(this.Index); } else { DataGridViewRowCollection dataGridViewRows = this.DataGridView.Rows; int rowCount = dataGridViewRows.Count; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex); DataGridViewButtonCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewButtonCell; if (dataGridViewCell != null && dataGridViewCell.UseColumnTextForButtonValue) { this.DataGridView.OnColumnCommonChange(this.Index); return; } } this.DataGridView.InvalidateColumn(this.Index); } } } } } /// [ DefaultValue(false), SRCategory(SR.CatAppearance), SRDescription(SR.DataGridView_ButtonColumnUseColumnTextForButtonValueDescr) ] public bool UseColumnTextForButtonValue { get { if (this.CellTemplate == null) { throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired)); } return ((DataGridViewButtonCell)this.CellTemplate).UseColumnTextForButtonValue; } set { if (this.UseColumnTextForButtonValue != value) { ((DataGridViewButtonCell)this.CellTemplate).UseColumnTextForButtonValueInternal = value; if (this.DataGridView != null) { DataGridViewRowCollection dataGridViewRows = this.DataGridView.Rows; int rowCount = dataGridViewRows.Count; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex); DataGridViewButtonCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewButtonCell; if (dataGridViewCell != null) { dataGridViewCell.UseColumnTextForButtonValueInternal = value; } } this.DataGridView.OnColumnCommonChange(this.Index); } } } } /// public override object Clone() { DataGridViewButtonColumn dataGridViewColumn; Type thisType = this.GetType(); if (thisType == columnType) //performance improvement { dataGridViewColumn = new DataGridViewButtonColumn(); } else { // SECREVIEW : Late-binding does not represent a security thread, see bug#411899 for more info.. // dataGridViewColumn = (DataGridViewButtonColumn) System.Activator.CreateInstance(thisType); } if (dataGridViewColumn != null) { base.CloneInternal(dataGridViewColumn); dataGridViewColumn.Text = this.text; } return dataGridViewColumn; } private bool ShouldSerializeDefaultCellStyle() { if (!this.HasDefaultCellStyle) { return false; } DataGridViewCellStyle defaultCellStyle = this.DefaultCellStyle; return (!defaultCellStyle.BackColor.IsEmpty || !defaultCellStyle.ForeColor.IsEmpty || !defaultCellStyle.SelectionBackColor.IsEmpty || !defaultCellStyle.SelectionForeColor.IsEmpty || defaultCellStyle.Font != null || !defaultCellStyle.IsNullValueDefault || !defaultCellStyle.IsDataSourceNullValueDefault || !String.IsNullOrEmpty(defaultCellStyle.Format) || !defaultCellStyle.FormatProvider.Equals(System.Globalization.CultureInfo.CurrentCulture) || defaultCellStyle.Alignment != DataGridViewContentAlignment.MiddleCenter || defaultCellStyle.WrapMode != DataGridViewTriState.NotSet || defaultCellStyle.Tag != null || !defaultCellStyle.Padding.Equals(Padding.Empty)); } /// public override string ToString() { StringBuilder sb = new StringBuilder(64); sb.Append("DataGridViewButtonColumn { Name="); sb.Append(this.Name); sb.Append(", Index="); sb.Append(this.Index.ToString(CultureInfo.CurrentCulture)); sb.Append(" }"); return sb.ToString(); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CroppedBitmap.cs
- FixedTextPointer.cs
- ValidationRule.cs
- CellIdBoolean.cs
- SizeIndependentAnimationStorage.cs
- BackgroundWorker.cs
- WmlControlAdapter.cs
- EditorZoneBase.cs
- ImageFormat.cs
- ConfigurationElementCollection.cs
- XmlSecureResolver.cs
- DataSetMappper.cs
- ExpandedWrapper.cs
- BlurBitmapEffect.cs
- SafeBitVector32.cs
- MailAddressCollection.cs
- ProfileModule.cs
- StorageFunctionMapping.cs
- EditorPartChrome.cs
- NTAccount.cs
- HttpClientProtocol.cs
- NullableDecimalSumAggregationOperator.cs
- DoWorkEventArgs.cs
- IsolatedStorage.cs
- TextTreeRootTextBlock.cs
- SafeMarshalContext.cs
- PngBitmapEncoder.cs
- MouseGesture.cs
- XmlSchemaObjectCollection.cs
- ScrollViewerAutomationPeer.cs
- MemberCollection.cs
- RsaSecurityTokenAuthenticator.cs
- WSTrustFeb2005.cs
- WebPartCancelEventArgs.cs
- InheritanceAttribute.cs
- RegisteredHiddenField.cs
- WebConfigurationFileMap.cs
- EntityReference.cs
- RowParagraph.cs
- ToolStripItemEventArgs.cs
- DataBindingCollection.cs
- webeventbuffer.cs
- HwndHost.cs
- LineServicesCallbacks.cs
- DeviceContext.cs
- FormViewRow.cs
- PrintEvent.cs
- DataGridViewSelectedRowCollection.cs
- AppSecurityManager.cs
- WindowsRichEditRange.cs
- PageCache.cs
- ObjectQuery.cs
- PathSegmentCollection.cs
- DesignerActionHeaderItem.cs
- MatrixAnimationBase.cs
- HashMembershipCondition.cs
- DateTimeOffset.cs
- DataObjectCopyingEventArgs.cs
- tibetanshape.cs
- PreviewKeyDownEventArgs.cs
- EntityDesignPluralizationHandler.cs
- EmbeddedMailObjectsCollection.cs
- Tile.cs
- NotCondition.cs
- BufferModeSettings.cs
- XmlWhitespace.cs
- HandleRef.cs
- PeerEndPoint.cs
- InputLangChangeEvent.cs
- CheckableControlBaseAdapter.cs
- FilteredXmlReader.cs
- CompileLiteralTextParser.cs
- SHA384.cs
- GlobalAllocSafeHandle.cs
- ParallelLoopState.cs
- ArrangedElement.cs
- RequestCache.cs
- VisualStyleTypesAndProperties.cs
- log.cs
- ImageDrawing.cs
- TransformProviderWrapper.cs
- MsdtcClusterUtils.cs
- ProcessHostFactoryHelper.cs
- ObjectAnimationBase.cs
- Encoder.cs
- MenuCommandService.cs
- TargetPerspective.cs
- PropertyConverter.cs
- ObjectNavigationPropertyMapping.cs
- BaseUriHelper.cs
- SqlProcedureAttribute.cs
- DiscoveryClientBindingElement.cs
- InputScopeManager.cs
- DependencyStoreSurrogate.cs
- FileController.cs
- BamlResourceDeserializer.cs
- DataGridViewDataConnection.cs
- AttributeTableBuilder.cs
- ValueUtilsSmi.cs
- HandlerFactoryWrapper.cs