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 / DataGridViewImageColumn.cs / 1 / DataGridViewImageColumn.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
///
[ToolboxBitmapAttribute(typeof(DataGridViewImageColumn), "DataGridViewImageColumn.bmp")]
public class DataGridViewImageColumn : DataGridViewColumn
{
private static Type columnType = typeof(DataGridViewImageColumn);
private Image image;
private Icon icon;
///
public DataGridViewImageColumn() : this(false /*valuesAreIcons*/)
{
}
///
[
SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // Can't think of a workaround.
]
public DataGridViewImageColumn(bool valuesAreIcons)
: base(new DataGridViewImageCell(valuesAreIcons))
{
DataGridViewCellStyle defaultCellStyle = new DataGridViewCellStyle();
defaultCellStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleCenter;
if (valuesAreIcons)
{
defaultCellStyle.NullValue = DataGridViewImageCell.ErrorIcon;
}
else
{
defaultCellStyle.NullValue = DataGridViewImageCell.ErrorBitmap;
}
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.DataGridViewImageCell))
{
throw new InvalidCastException(SR.GetString(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewImageCell"));
}
base.CellTemplate = value;
}
}
///
[
Browsable(true),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridView_ColumnDefaultCellStyleDescr)
]
public override DataGridViewCellStyle DefaultCellStyle
{
get
{
return base.DefaultCellStyle;
}
set
{
base.DefaultCellStyle = value;
}
}
///
[
Browsable(true),
DefaultValue(""),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridViewImageColumn_DescriptionDescr)
]
public string Description
{
get
{
if (this.CellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
return this.ImageCellTemplate.Description;
}
set
{
if (this.CellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
this.ImageCellTemplate.Description = 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);
DataGridViewImageCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewImageCell;
if (dataGridViewCell != null)
{
dataGridViewCell.Description = value;
}
}
}
}
}
///
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public Icon Icon
{
get
{
return this.icon;
}
set
{
this.icon = value;
if (this.DataGridView != null)
{
this.DataGridView.OnColumnCommonChange(this.Index);
}
}
}
///
[
DefaultValue(null),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridViewImageColumn_ImageDescr)
]
public Image Image
{
get
{
return this.image;
}
set
{
this.image = value;
if (this.DataGridView != null)
{
this.DataGridView.OnColumnCommonChange(this.Index);
}
}
}
private DataGridViewImageCell ImageCellTemplate
{
get
{
return (DataGridViewImageCell) this.CellTemplate;
}
}
///
[
DefaultValue(DataGridViewImageCellLayout.Normal),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridViewImageColumn_ImageLayoutDescr)
]
public DataGridViewImageCellLayout ImageLayout
{
get
{
if (this.CellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
DataGridViewImageCellLayout imageLayout = this.ImageCellTemplate.ImageLayout;
if (imageLayout == DataGridViewImageCellLayout.NotSet)
{
imageLayout = DataGridViewImageCellLayout.Normal;
}
return imageLayout;
}
set
{
if (this.ImageLayout != value)
{
this.ImageCellTemplate.ImageLayout = 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);
DataGridViewImageCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewImageCell;
if (dataGridViewCell != null)
{
dataGridViewCell.ImageLayoutInternal = value;
}
}
this.DataGridView.OnColumnCommonChange(this.Index);
}
}
}
}
///
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public bool ValuesAreIcons
{
get
{
if (this.ImageCellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
return this.ImageCellTemplate.ValueIsIcon;
}
set
{
if (this.ValuesAreIcons != value)
{
this.ImageCellTemplate.ValueIsIconInternal = 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);
DataGridViewImageCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewImageCell;
if (dataGridViewCell != null)
{
dataGridViewCell.ValueIsIconInternal = value;
}
}
this.DataGridView.OnColumnCommonChange(this.Index);
}
if (value &&
this.DefaultCellStyle.NullValue is Bitmap &&
(Bitmap) this.DefaultCellStyle.NullValue == DataGridViewImageCell.ErrorBitmap)
{
this.DefaultCellStyle.NullValue = DataGridViewImageCell.ErrorIcon;
}
else if (!value &&
this.DefaultCellStyle.NullValue is Icon &&
(Icon) this.DefaultCellStyle.NullValue == DataGridViewImageCell.ErrorIcon)
{
this.DefaultCellStyle.NullValue = DataGridViewImageCell.ErrorBitmap;
}
}
}
}
///
public override object Clone()
{
DataGridViewImageColumn dataGridViewColumn;
Type thisType = this.GetType();
if (thisType == columnType) //performance improvement
{
dataGridViewColumn = new DataGridViewImageColumn();
}
else
{
// SECREVIEW : Late-binding does not represent a security thread, see bug#411899 for more info..
//
dataGridViewColumn = (DataGridViewImageColumn)System.Activator.CreateInstance(thisType);
}
if (dataGridViewColumn != null)
{
base.CloneInternal(dataGridViewColumn);
dataGridViewColumn.Icon = this.icon;
dataGridViewColumn.Image = this.image;
}
return dataGridViewColumn;
}
private bool ShouldSerializeDefaultCellStyle()
{
DataGridViewImageCell templateCell = this.CellTemplate as DataGridViewImageCell;
if (templateCell == null)
{
Debug.Fail("we can't compute the default cell style w/o a template cell");
return true;
}
if (!this.HasDefaultCellStyle)
{
return false;
}
object defaultNullValue;
if (templateCell.ValueIsIcon)
{
defaultNullValue = DataGridViewImageCell.ErrorIcon;
}
else
{
defaultNullValue = DataGridViewImageCell.ErrorBitmap;
}
DataGridViewCellStyle defaultCellStyle = this.DefaultCellStyle;
return (!defaultCellStyle.BackColor.IsEmpty ||
!defaultCellStyle.ForeColor.IsEmpty ||
!defaultCellStyle.SelectionBackColor.IsEmpty ||
!defaultCellStyle.SelectionForeColor.IsEmpty ||
defaultCellStyle.Font != null ||
!defaultNullValue.Equals(defaultCellStyle.NullValue) ||
!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("DataGridViewImageColumn { 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.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
///
[ToolboxBitmapAttribute(typeof(DataGridViewImageColumn), "DataGridViewImageColumn.bmp")]
public class DataGridViewImageColumn : DataGridViewColumn
{
private static Type columnType = typeof(DataGridViewImageColumn);
private Image image;
private Icon icon;
///
public DataGridViewImageColumn() : this(false /*valuesAreIcons*/)
{
}
///
[
SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // Can't think of a workaround.
]
public DataGridViewImageColumn(bool valuesAreIcons)
: base(new DataGridViewImageCell(valuesAreIcons))
{
DataGridViewCellStyle defaultCellStyle = new DataGridViewCellStyle();
defaultCellStyle.AlignmentInternal = DataGridViewContentAlignment.MiddleCenter;
if (valuesAreIcons)
{
defaultCellStyle.NullValue = DataGridViewImageCell.ErrorIcon;
}
else
{
defaultCellStyle.NullValue = DataGridViewImageCell.ErrorBitmap;
}
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.DataGridViewImageCell))
{
throw new InvalidCastException(SR.GetString(SR.DataGridViewTypeColumn_WrongCellTemplateType, "System.Windows.Forms.DataGridViewImageCell"));
}
base.CellTemplate = value;
}
}
///
[
Browsable(true),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridView_ColumnDefaultCellStyleDescr)
]
public override DataGridViewCellStyle DefaultCellStyle
{
get
{
return base.DefaultCellStyle;
}
set
{
base.DefaultCellStyle = value;
}
}
///
[
Browsable(true),
DefaultValue(""),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridViewImageColumn_DescriptionDescr)
]
public string Description
{
get
{
if (this.CellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
return this.ImageCellTemplate.Description;
}
set
{
if (this.CellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
this.ImageCellTemplate.Description = 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);
DataGridViewImageCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewImageCell;
if (dataGridViewCell != null)
{
dataGridViewCell.Description = value;
}
}
}
}
}
///
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public Icon Icon
{
get
{
return this.icon;
}
set
{
this.icon = value;
if (this.DataGridView != null)
{
this.DataGridView.OnColumnCommonChange(this.Index);
}
}
}
///
[
DefaultValue(null),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridViewImageColumn_ImageDescr)
]
public Image Image
{
get
{
return this.image;
}
set
{
this.image = value;
if (this.DataGridView != null)
{
this.DataGridView.OnColumnCommonChange(this.Index);
}
}
}
private DataGridViewImageCell ImageCellTemplate
{
get
{
return (DataGridViewImageCell) this.CellTemplate;
}
}
///
[
DefaultValue(DataGridViewImageCellLayout.Normal),
SRCategory(SR.CatAppearance),
SRDescription(SR.DataGridViewImageColumn_ImageLayoutDescr)
]
public DataGridViewImageCellLayout ImageLayout
{
get
{
if (this.CellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
DataGridViewImageCellLayout imageLayout = this.ImageCellTemplate.ImageLayout;
if (imageLayout == DataGridViewImageCellLayout.NotSet)
{
imageLayout = DataGridViewImageCellLayout.Normal;
}
return imageLayout;
}
set
{
if (this.ImageLayout != value)
{
this.ImageCellTemplate.ImageLayout = 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);
DataGridViewImageCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewImageCell;
if (dataGridViewCell != null)
{
dataGridViewCell.ImageLayoutInternal = value;
}
}
this.DataGridView.OnColumnCommonChange(this.Index);
}
}
}
}
///
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
public bool ValuesAreIcons
{
get
{
if (this.ImageCellTemplate == null)
{
throw new InvalidOperationException(SR.GetString(SR.DataGridViewColumn_CellTemplateRequired));
}
return this.ImageCellTemplate.ValueIsIcon;
}
set
{
if (this.ValuesAreIcons != value)
{
this.ImageCellTemplate.ValueIsIconInternal = 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);
DataGridViewImageCell dataGridViewCell = dataGridViewRow.Cells[this.Index] as DataGridViewImageCell;
if (dataGridViewCell != null)
{
dataGridViewCell.ValueIsIconInternal = value;
}
}
this.DataGridView.OnColumnCommonChange(this.Index);
}
if (value &&
this.DefaultCellStyle.NullValue is Bitmap &&
(Bitmap) this.DefaultCellStyle.NullValue == DataGridViewImageCell.ErrorBitmap)
{
this.DefaultCellStyle.NullValue = DataGridViewImageCell.ErrorIcon;
}
else if (!value &&
this.DefaultCellStyle.NullValue is Icon &&
(Icon) this.DefaultCellStyle.NullValue == DataGridViewImageCell.ErrorIcon)
{
this.DefaultCellStyle.NullValue = DataGridViewImageCell.ErrorBitmap;
}
}
}
}
///
public override object Clone()
{
DataGridViewImageColumn dataGridViewColumn;
Type thisType = this.GetType();
if (thisType == columnType) //performance improvement
{
dataGridViewColumn = new DataGridViewImageColumn();
}
else
{
// SECREVIEW : Late-binding does not represent a security thread, see bug#411899 for more info..
//
dataGridViewColumn = (DataGridViewImageColumn)System.Activator.CreateInstance(thisType);
}
if (dataGridViewColumn != null)
{
base.CloneInternal(dataGridViewColumn);
dataGridViewColumn.Icon = this.icon;
dataGridViewColumn.Image = this.image;
}
return dataGridViewColumn;
}
private bool ShouldSerializeDefaultCellStyle()
{
DataGridViewImageCell templateCell = this.CellTemplate as DataGridViewImageCell;
if (templateCell == null)
{
Debug.Fail("we can't compute the default cell style w/o a template cell");
return true;
}
if (!this.HasDefaultCellStyle)
{
return false;
}
object defaultNullValue;
if (templateCell.ValueIsIcon)
{
defaultNullValue = DataGridViewImageCell.ErrorIcon;
}
else
{
defaultNullValue = DataGridViewImageCell.ErrorBitmap;
}
DataGridViewCellStyle defaultCellStyle = this.DefaultCellStyle;
return (!defaultCellStyle.BackColor.IsEmpty ||
!defaultCellStyle.ForeColor.IsEmpty ||
!defaultCellStyle.SelectionBackColor.IsEmpty ||
!defaultCellStyle.SelectionForeColor.IsEmpty ||
defaultCellStyle.Font != null ||
!defaultNullValue.Equals(defaultCellStyle.NullValue) ||
!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("DataGridViewImageColumn { 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
- MatrixConverter.cs
- MatrixTransform3D.cs
- DeclarativeExpressionConditionDeclaration.cs
- XmlSchemaComplexType.cs
- StringValidatorAttribute.cs
- DataBindingCollectionConverter.cs
- ReaderWriterLock.cs
- Journal.cs
- WebPartDisplayModeEventArgs.cs
- BindingMAnagerBase.cs
- SimpleApplicationHost.cs
- PopOutPanel.cs
- DictionarySectionHandler.cs
- DictionaryKeyPropertyAttribute.cs
- AvtEvent.cs
- ExtensionQuery.cs
- ProcessModelInfo.cs
- ProtocolException.cs
- AnnouncementSendsAsyncResult.cs
- control.ime.cs
- BitmapImage.cs
- CngAlgorithm.cs
- BaseDataListActionList.cs
- __FastResourceComparer.cs
- RegexGroup.cs
- EventSourceCreationData.cs
- SqlDataSourceCommandEventArgs.cs
- StrokeDescriptor.cs
- RoutedCommand.cs
- ZoomPercentageConverter.cs
- SafeFileMappingHandle.cs
- ValueUnavailableException.cs
- RelativeSource.cs
- VSWCFServiceContractGenerator.cs
- RegularExpressionValidator.cs
- TableLayoutColumnStyleCollection.cs
- ToolStripPanelCell.cs
- FixedSOMImage.cs
- IgnoreFlushAndCloseStream.cs
- SHA256.cs
- ScriptHandlerFactory.cs
- TextPointer.cs
- QuarticEase.cs
- AdRotatorDesigner.cs
- ObjectReaderCompiler.cs
- SqlDataSourceParameterParser.cs
- BaseDataListDesigner.cs
- PointValueSerializer.cs
- InstalledFontCollection.cs
- ExpressionVisitor.cs
- TargetParameterCountException.cs
- SemaphoreSecurity.cs
- OdbcCommandBuilder.cs
- TreeSet.cs
- CodeTypeParameterCollection.cs
- CompiledXpathExpr.cs
- Screen.cs
- HttpRawResponse.cs
- ConnectionOrientedTransportBindingElement.cs
- AccessDataSource.cs
- ConfigXmlCDataSection.cs
- HwndSourceKeyboardInputSite.cs
- ImageListStreamer.cs
- DoWorkEventArgs.cs
- validation.cs
- ApplicationTrust.cs
- StandardCommands.cs
- DataGridCommandEventArgs.cs
- BaseTemplateBuildProvider.cs
- Light.cs
- ReadWriteObjectLock.cs
- HashMembershipCondition.cs
- KeyManager.cs
- DataPagerCommandEventArgs.cs
- ExpressionQuoter.cs
- WebCategoryAttribute.cs
- PolyQuadraticBezierSegment.cs
- RtfControls.cs
- SiteMapPathDesigner.cs
- Preprocessor.cs
- ChannelFactoryBase.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- ZoneLinkButton.cs
- SignatureDescription.cs
- RootBrowserWindowAutomationPeer.cs
- MenuEventArgs.cs
- CompiledRegexRunner.cs
- ProvidersHelper.cs
- TablePattern.cs
- ButtonChrome.cs
- FrameworkTextComposition.cs
- CustomErrorCollection.cs
- TextTabProperties.cs
- Application.cs
- WebBrowserNavigatedEventHandler.cs
- ConfigXmlCDataSection.cs
- PreservationFileReader.cs
- ParameterReplacerVisitor.cs
- LayoutExceptionEventArgs.cs
- CodeMethodReturnStatement.cs