Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / WebControls / DataGridDesigner.cs / 1 / DataGridDesigner.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.WebControls {
using System;
using System.Design;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
///
///
///
/// This is the designer class for the
/// control.
///
///
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
[SupportsPreviewControl(true)]
public class DataGridDesigner : BaseDataListDesigner {
internal static TraceSwitch DataGridDesignerSwitch =
new TraceSwitch("DATAGRIDDESIGNER", "Enable DataGrid designer general purpose traces.");
private static string[] ColumnTemplateNames = new string[] { "ItemTemplate", "EditItemTemplate", "HeaderTemplate", "FooterTemplate" };
private const int IDX_HEADER_TEMPLATE = 2;
private const int IDX_ITEM_TEMPLATE = 0;
private const int IDX_EDITITEM_TEMPLATE = 1;
private const int IDX_FOOTER_TEMPLATE = 3;
#pragma warning disable 618
private TemplateEditingVerb[] templateVerbs;
#pragma warning restore 618
private bool templateVerbsDirty;
private static DesignerAutoFormatCollection _autoFormats;
///
///
///
/// Initializes a new instance of .
///
///
public DataGridDesigner() {
templateVerbsDirty = true;
}
public override DesignerAutoFormatCollection AutoFormats {
get {
if (_autoFormats == null) {
_autoFormats = CreateAutoFormats(AutoFormatSchemes.BDL_SCHEMES,
delegate(DataRow schemeData) { return new DataGridAutoFormat(schemeData); });
}
return _autoFormats;
}
}
///
[Obsolete("Use of this method is not recommended because template editing is handled in ControlDesigner. To support template editing expose template data in the TemplateGroups property and call SetViewFlags(ViewFlags.TemplateEditing, true). http://go.microsoft.com/fwlink/?linkid=14202")]
protected override ITemplateEditingFrame CreateTemplateEditingFrame(TemplateEditingVerb verb) {
ITemplateEditingService teService = (ITemplateEditingService)GetService(typeof(ITemplateEditingService));
Debug.Assert(teService != null, "How did we get this far without an ITemplateEditingService");
DataGrid grid = (DataGrid)ViewControl;
Style[] templateStyles = new Style[] { grid.ItemStyle, grid.EditItemStyle, grid.HeaderStyle, grid.FooterStyle };
ITemplateEditingFrame editingFrame =
teService.CreateFrame(this, verb.Text, ColumnTemplateNames, grid.ControlStyle, templateStyles);
return editingFrame;
}
///
protected override void Dispose(bool disposing) {
if (disposing) {
DisposeTemplateVerbs();
}
base.Dispose(disposing);
}
private void DisposeTemplateVerbs() {
if (templateVerbs != null) {
for (int i = 0; i < templateVerbs.Length; i++) {
templateVerbs[i].Dispose();
}
templateVerbs = null;
templateVerbsDirty = true;
}
}
///
[Obsolete("Use of this method is not recommended because template editing is handled in ControlDesigner. To support template editing expose template data in the TemplateGroups property and call SetViewFlags(ViewFlags.TemplateEditing, true). http://go.microsoft.com/fwlink/?linkid=14202")]
protected override TemplateEditingVerb[] GetCachedTemplateEditingVerbs() {
if (templateVerbsDirty == true) {
DisposeTemplateVerbs();
DataGridColumnCollection columns = ((DataGrid)Component).Columns;
int columnCount = columns.Count;
if (columnCount > 0) {
int templateColumns = 0;
int i, t;
for (i = 0; i < columnCount; i++) {
if (columns[i] is TemplateColumn) {
templateColumns++;
}
}
if (templateColumns > 0) {
templateVerbs = new TemplateEditingVerb[templateColumns];
for (i = 0, t = 0; i < columnCount; i++) {
if (columns[i] is TemplateColumn) {
string headerText = columns[i].HeaderText;
string caption = "Columns[" + i.ToString(NumberFormatInfo.CurrentInfo) + "]";
if ((headerText != null) && (headerText.Length != 0)) {
caption = caption + " - " + headerText;
}
templateVerbs[t] = new TemplateEditingVerb(caption, i, this);
t++;
}
}
}
}
templateVerbsDirty = false;
}
return templateVerbs;
}
///
///
///
/// Gets the HTML to be used for the design time representation
/// of the control.
///
///
public override string GetDesignTimeHtml() {
int sampleRows = 5;
DataGrid dataGrid = (DataGrid)ViewControl;
// ensure there are enough sample rows to show an entire page, and still
// have 1 more for a navigation button to be enabled
// we also want to ensure we don't have something ridiculously large
if (dataGrid.AllowPaging && dataGrid.PageSize != 0) {
sampleRows = Math.Min(dataGrid.PageSize, 100) + 1;
}
bool dummyDataSource = false;
IEnumerable designTimeDataSource = null;
bool autoGenColumnsChanged = false;
bool dataKeyFieldChanged = false;
bool dataSourceIDChanged = false;
DesignerDataSourceView view = DesignerView;
bool oldAutoGenColumns = dataGrid.AutoGenerateColumns;
string oldDataKeyField = String.Empty;
string oldDataSourceID = String.Empty;
string designTimeHTML = null;
if (view == null) {
designTimeDataSource = GetDesignTimeDataSource(sampleRows, out dummyDataSource);
}
else {
try {
designTimeDataSource = view.GetDesignTimeData(sampleRows, out dummyDataSource);
}
catch (Exception ex) {
if (Component.Site != null) {
IComponentDesignerDebugService debugService = (IComponentDesignerDebugService)Component.Site.GetService(typeof(IComponentDesignerDebugService));
if (debugService != null) {
debugService.Fail(SR.GetString(SR.DataSource_DebugService_FailedCall, "DesignerDataSourceView.GetDesignTimeData", ex.Message));
}
}
}
if (designTimeDataSource == null) {
Debug.Assert(false, "DataBoundControlDesigner::GetDesignTimeHtml - DesignTimeDataSource was null.");
return GetEmptyDesignTimeHtml();
}
}
if ((oldAutoGenColumns == false) && (dataGrid.Columns.Count == 0)) {
// ensure that AutoGenerateColumns is true when we don't have
// a columns collection, so we see atleast something at
// design time.
autoGenColumnsChanged = true;
dataGrid.AutoGenerateColumns = true;
}
if (dummyDataSource) {
oldDataKeyField = dataGrid.DataKeyField;
if (oldDataKeyField.Length != 0) {
dataKeyFieldChanged = true;
dataGrid.DataKeyField = String.Empty;
}
}
try {
dataGrid.DataSource = designTimeDataSource;
oldDataSourceID = dataGrid.DataSourceID;
dataGrid.DataSourceID = String.Empty;
dataSourceIDChanged = true;
dataGrid.DataBind();
designTimeHTML = base.GetDesignTimeHtml();
}
catch (Exception e) {
designTimeHTML = GetErrorDesignTimeHtml(e);
}
finally {
// restore settings we changed for rendering purposes
dataGrid.DataSource = null;
if (autoGenColumnsChanged) {
dataGrid.AutoGenerateColumns = false;
}
if (dataKeyFieldChanged == true) {
dataGrid.DataKeyField = oldDataKeyField;
}
if (dataSourceIDChanged == true) {
dataGrid.DataSourceID = oldDataSourceID;
}
}
return designTimeHTML;
}
///
///
///
protected override string GetEmptyDesignTimeHtml() {
return CreatePlaceHolderDesignTimeHtml(null);
}
///
///
///
protected override string GetErrorDesignTimeHtml(Exception e) {
Debug.Fail(e.ToString());
return CreatePlaceHolderDesignTimeHtml(SR.GetString(SR.Control_ErrorRendering));
}
///
///
///
/// Gets the template's container's data item property.
///
///
[Obsolete("Use of this method is not recommended because template editing is handled in ControlDesigner. To support template editing expose template data in the TemplateGroups property and call SetViewFlags(ViewFlags.TemplateEditing, true). http://go.microsoft.com/fwlink/?linkid=14202")]
public override string GetTemplateContainerDataItemProperty(string templateName) {
return "DataItem";
}
///
///
///
/// Gets the template's content.
///
///
[Obsolete("Use of this method is not recommended because template editing is handled in ControlDesigner. To support template editing expose template data in the TemplateGroups property and call SetViewFlags(ViewFlags.TemplateEditing, true). http://go.microsoft.com/fwlink/?linkid=14202")]
public override string GetTemplateContent(ITemplateEditingFrame editingFrame, string templateName, out bool allowEditing) {
allowEditing = true;
DataGrid dataGrid = (DataGrid)Component;
int columnIndex = editingFrame.Verb.Index;
Debug.Assert((columnIndex >= 0) && (columnIndex < dataGrid.Columns.Count),
"Invalid column index in template editing frame.");
Debug.Assert(dataGrid.Columns[columnIndex] is TemplateColumn,
"Template editing frame points to a non-TemplateColumn column.");
TemplateColumn column = (TemplateColumn)dataGrid.Columns[columnIndex];
ITemplate template = null;
string templateContent = String.Empty;
if (templateName.Equals(ColumnTemplateNames[IDX_HEADER_TEMPLATE])) {
template = column.HeaderTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_ITEM_TEMPLATE])) {
template = column.ItemTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_EDITITEM_TEMPLATE])) {
template = column.EditItemTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_FOOTER_TEMPLATE])) {
template = column.FooterTemplate;
}
else {
Debug.Fail("Unknown template name passed to GetTemplateContent");
}
if (template != null) {
templateContent = GetTextFromTemplate(template);
}
return templateContent;
}
///
[Obsolete("Use of this method is not recommended because template editing is handled in ControlDesigner. To support template editing expose template data in the TemplateGroups property and call SetViewFlags(ViewFlags.TemplateEditing, true). http://go.microsoft.com/fwlink/?linkid=14202")]
public override Type GetTemplatePropertyParentType(string templateName) {
return typeof(TemplateColumn);
}
///
///
///
/// Notification that is called when the columns changed event occurs.
///
///
public virtual void OnColumnsChanged() {
OnTemplateEditingVerbsChanged();
}
///
protected override void OnTemplateEditingVerbsChanged() {
templateVerbsDirty = true;
}
///
///
/// Initializes the designer with the DataGrid control that this instance
/// of the designer is associated with.
///
public override void Initialize(IComponent component) {
VerifyInitializeArgument(component, typeof(DataGrid));
base.Initialize(component);
}
///
///
///
/// Sets the content for the specified template and frame.
///
///
[Obsolete("Use of this method is not recommended because template editing is handled in ControlDesigner. To support template editing expose template data in the TemplateGroups property and call SetViewFlags(ViewFlags.TemplateEditing, true). http://go.microsoft.com/fwlink/?linkid=14202")]
public override void SetTemplateContent(ITemplateEditingFrame editingFrame, string templateName, string templateContent) {
int columnIndex = editingFrame.Verb.Index;
DataGrid dataGrid = (DataGrid)Component;
Debug.Assert((columnIndex >= 0) && (columnIndex < dataGrid.Columns.Count),
"Invalid column index in template editing frame.");
Debug.Assert(dataGrid.Columns[columnIndex] is TemplateColumn,
"Template editing frame points to a non-TemplateColumn column.");
TemplateColumn column = (TemplateColumn)dataGrid.Columns[columnIndex];
ITemplate newTemplate = null;
if ((templateContent != null) && (templateContent.Length != 0)) {
ITemplate currentTemplate = null;
// first get the current template so we can use it if we fail to parse the
// new text into a template
if (templateName.Equals(ColumnTemplateNames[IDX_HEADER_TEMPLATE])) {
currentTemplate = column.HeaderTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_ITEM_TEMPLATE])) {
currentTemplate = column.ItemTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_EDITITEM_TEMPLATE])) {
currentTemplate = column.EditItemTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_FOOTER_TEMPLATE])) {
currentTemplate = column.FooterTemplate;
}
// this will parse out a new template, and if it fails, it will
// return currentTemplate itself
newTemplate = GetTemplateFromText(templateContent, currentTemplate);
}
// Set the new template into the control. Note this may be null, if the
// template content was empty, i.e., the user cleared out everything in the UI.
if (templateName.Equals(ColumnTemplateNames[IDX_HEADER_TEMPLATE])) {
column.HeaderTemplate = newTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_ITEM_TEMPLATE])) {
column.ItemTemplate = newTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_EDITITEM_TEMPLATE])) {
column.EditItemTemplate = newTemplate;
}
else if (templateName.Equals(ColumnTemplateNames[IDX_FOOTER_TEMPLATE])) {
column.FooterTemplate = newTemplate;
}
else {
Debug.Fail("Unknown template name passed to SetTemplateContent");
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextRangeEditTables.cs
- SerializationObjectManager.cs
- InfiniteIntConverter.cs
- EncryptedData.cs
- DesignTimeParseData.cs
- Selector.cs
- UrlMappingsModule.cs
- XmlSchemaObjectCollection.cs
- WeakEventTable.cs
- TextStore.cs
- PagePropertiesChangingEventArgs.cs
- ProgressBarRenderer.cs
- ResolvedKeyFrameEntry.cs
- DictionarySectionHandler.cs
- List.cs
- SurrogateDataContract.cs
- BaseCAMarshaler.cs
- ParseChildrenAsPropertiesAttribute.cs
- HttpServerUtilityWrapper.cs
- LineServicesRun.cs
- DeclaredTypeValidator.cs
- TrackingRecord.cs
- IndexedGlyphRun.cs
- _CookieModule.cs
- ConnectionPointCookie.cs
- WindowProviderWrapper.cs
- ResXResourceReader.cs
- QilStrConcat.cs
- IsolatedStorageFile.cs
- Point3D.cs
- METAHEADER.cs
- XsdDuration.cs
- ISAPIRuntime.cs
- SafeNativeHandle.cs
- MimeParameter.cs
- WorkflowView.cs
- CompressStream.cs
- SoapIgnoreAttribute.cs
- InheritanceUI.cs
- DesignTimeValidationFeature.cs
- CustomCategoryAttribute.cs
- DetailsViewUpdateEventArgs.cs
- Decorator.cs
- DomNameTable.cs
- Monitor.cs
- ICollection.cs
- HuffmanTree.cs
- SerTrace.cs
- DataGridViewRowsRemovedEventArgs.cs
- PathTooLongException.cs
- ThicknessAnimationUsingKeyFrames.cs
- MLangCodePageEncoding.cs
- AutomationPatternInfo.cs
- QueryCacheEntry.cs
- GraphicsPathIterator.cs
- AssemblyBuilder.cs
- GridViewRowPresenterBase.cs
- CrossSiteScriptingValidation.cs
- CodeChecksumPragma.cs
- SnapshotChangeTrackingStrategy.cs
- NameValueConfigurationElement.cs
- StorageMappingFragment.cs
- __FastResourceComparer.cs
- XmlQueryCardinality.cs
- EntityModelBuildProvider.cs
- Point3DCollection.cs
- WebDescriptionAttribute.cs
- TypefaceMetricsCache.cs
- LassoSelectionBehavior.cs
- DataPagerCommandEventArgs.cs
- CodeGen.cs
- ListViewInsertedEventArgs.cs
- OdbcConnection.cs
- StylesEditorDialog.cs
- XmlSchemaDocumentation.cs
- PersistenceParticipant.cs
- DataGridViewCellStyleConverter.cs
- CqlParserHelpers.cs
- LocalizabilityAttribute.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- DispatcherSynchronizationContext.cs
- CodeDomConfigurationHandler.cs
- ColumnReorderedEventArgs.cs
- CmsInterop.cs
- CompilerScopeManager.cs
- PartialList.cs
- XmlUtil.cs
- PackageFilter.cs
- OutputScopeManager.cs
- XmlSchemaAttributeGroupRef.cs
- HandlerFactoryWrapper.cs
- PerspectiveCamera.cs
- ConfigurationValidatorAttribute.cs
- ObjectViewListener.cs
- SqlProviderManifest.cs
- MessageDispatch.cs
- ProfileEventArgs.cs
- CommandHelper.cs
- ConversionContext.cs
- Int64Storage.cs