Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / WebControls / DataSourceIDConverter.cs / 1 / DataSourceIDConverter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.WebControls {
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.Design;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Collections.Generic;
///
public class DataSourceIDConverter : TypeConverter {
///
public DataSourceIDConverter() {
}
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string)) {
return true;
}
return false;
}
///
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value == null) {
return String.Empty;
}
else if (value.GetType() == typeof(string)) {
return (string)value;
}
throw GetConvertFromException(value);
}
///
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
string[] idsArray = null;
if (context != null) {
WebFormsRootDesigner rootDesigner = null;
IDesignerHost designerHost = (IDesignerHost)(context.GetService(typeof(IDesignerHost)));
Debug.Assert(designerHost != null, "Did not get DesignerHost service.");
if (designerHost != null) {
IComponent rootComponent = designerHost.RootComponent;
if (rootComponent != null) {
rootDesigner = designerHost.GetDesigner(rootComponent) as WebFormsRootDesigner;
}
}
if (rootDesigner != null && !rootDesigner.IsDesignerViewLocked) {
// Walk up the list of naming containers to get all accessible data sources
IComponent component = context.Instance as IComponent;
if (component == null) {
// In case we are hosted in a DesignerActionList we need
// to find out the component that the action list belongs to
DesignerActionList actionList = context.Instance as DesignerActionList;
if (actionList != null) {
component = actionList.Component;
}
}
IList allComponents = ControlHelper.GetAllComponents(component, new ControlHelper.IsValidComponentDelegate(IsValidDataSource));
List uniqueControlIDs = new List();
foreach (IComponent c in allComponents) {
Control control = c as Control;
if (control != null && !String.IsNullOrEmpty(control.ID)) {
if (!uniqueControlIDs.Contains(control.ID)) {
uniqueControlIDs.Add(control.ID);
}
}
}
uniqueControlIDs.Sort(StringComparer.OrdinalIgnoreCase);
uniqueControlIDs.Insert(0, SR.GetString(SR.DataSourceIDChromeConverter_NoDataSource));
uniqueControlIDs.Add(SR.GetString(SR.DataSourceIDChromeConverter_NewDataSource));
idsArray = uniqueControlIDs.ToArray();
}
}
return new StandardValuesCollection(idsArray);
}
///
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return false;
}
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
///
protected virtual bool IsValidDataSource(IComponent component) {
Control control = component as Control;
if (control == null) {
return false;
}
if (String.IsNullOrEmpty(control.ID)) {
return false;
}
return (component is IDataSource);
}
}
}
// 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
- WebPartDisplayModeEventArgs.cs
- DesignerDataColumn.cs
- IdentifierService.cs
- NextPreviousPagerField.cs
- CloudCollection.cs
- ToolboxBitmapAttribute.cs
- CapabilitiesState.cs
- DesignerAttribute.cs
- RuntimeVariableList.cs
- Zone.cs
- DeploymentExceptionMapper.cs
- PTManager.cs
- VectorValueSerializer.cs
- XmlCustomFormatter.cs
- BitmapSource.cs
- OutArgumentConverter.cs
- SQLInt32Storage.cs
- TransformPatternIdentifiers.cs
- X509SecurityTokenAuthenticator.cs
- EntityClassGenerator.cs
- ExpressionBuilderContext.cs
- StructuralType.cs
- RuntimeArgument.cs
- Automation.cs
- RowToParametersTransformer.cs
- GroupBox.cs
- PackageDigitalSignature.cs
- OdbcDataReader.cs
- ActiveXSite.cs
- ScrollProviderWrapper.cs
- ReadContentAsBinaryHelper.cs
- CommandEventArgs.cs
- JsonEnumDataContract.cs
- ScrollItemPattern.cs
- UrlUtility.cs
- MarkerProperties.cs
- ServiceMetadataContractBehavior.cs
- ItemContainerGenerator.cs
- TypeLoadException.cs
- ReturnValue.cs
- CollectionConverter.cs
- RegistrationServices.cs
- _OSSOCK.cs
- Shared.cs
- SchemaElement.cs
- SocketPermission.cs
- UnknownWrapper.cs
- DataGridViewRow.cs
- DataGridTableCollection.cs
- PropertyMapper.cs
- Utility.cs
- WindowsIdentity.cs
- StateElement.cs
- RoutedEventHandlerInfo.cs
- OpacityConverter.cs
- SessionState.cs
- WebHttpEndpoint.cs
- PageContentAsyncResult.cs
- DependencyPropertyDescriptor.cs
- StateMachine.cs
- MediaContext.cs
- FlowDocumentReader.cs
- RequestCacheEntry.cs
- BeginEvent.cs
- DefaultAssemblyResolver.cs
- FigureParaClient.cs
- IntegerFacetDescriptionElement.cs
- UriExt.cs
- MailHeaderInfo.cs
- TextControl.cs
- DatePickerDateValidationErrorEventArgs.cs
- EventPropertyMap.cs
- SiteMapSection.cs
- Brushes.cs
- ContentPathSegment.cs
- ScrollChrome.cs
- HttpListenerContext.cs
- GraphicsPathIterator.cs
- PolyBezierSegment.cs
- MsmqProcessProtocolHandler.cs
- CompatibleComparer.cs
- ColorTranslator.cs
- ResourceDisplayNameAttribute.cs
- documentsequencetextpointer.cs
- SspiNegotiationTokenProviderState.cs
- Transform.cs
- QilTypeChecker.cs
- SerializationTrace.cs
- ArraySortHelper.cs
- SafeProcessHandle.cs
- XmlQueryCardinality.cs
- OutputCacheSettingsSection.cs
- ColorBlend.cs
- PropertyGridEditorPart.cs
- MutableAssemblyCacheEntry.cs
- Zone.cs
- SingleAnimationBase.cs
- Missing.cs
- Vertex.cs
- FtpWebResponse.cs