Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / WebControls / ListControlDesigner.cs / 1 / ListControlDesigner.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.Diagnostics;
using System.IO;
using System.Data;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.Util;
using System.Web.UI.WebControls;
using System.Windows.Forms.Design;
using DialogResult = System.Windows.Forms.DialogResult;
using AttributeCollection = System.ComponentModel.AttributeCollection;
using DataBinding = System.Web.UI.DataBinding;
///
///
///
/// This is the base class for all
/// designers.
///
///
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
[SupportsPreviewControl(true)]
public class ListControlDesigner : DataBoundControlDesigner {
///
///
///
/// Initializes a new instance of
/// .
///
///
public ListControlDesigner() {
}
///
///
/// Adds designer actions to the ActionLists collection.
///
public override DesignerActionListCollection ActionLists {
get {
DesignerActionListCollection actionLists = new DesignerActionListCollection();
actionLists.AddRange(base.ActionLists);
actionLists.Add(new ListControlActionList(this, DataSourceDesigner));
return actionLists;
}
}
///
///
///
public string DataValueField {
get {
return ((ListControl)Component).DataValueField;
}
set {
((ListControl)Component).DataValueField = value;
}
}
///
///
/// Retrieves the HTML to be used for the design time representation of the control runtime.
///
public string DataTextField {
get {
return ((ListControl)Component).DataTextField;
}
set {
((ListControl)Component).DataTextField = value;
}
}
///
///
/// Used to determine whether the control should render its default action lists,
/// containing a DataSourceID dropdown and related tasks.
///
protected override bool UseDataSourcePickerActionList {
get {
return false;
}
}
internal void ConnectToDataSourceAction() {
InvokeTransactedChange(Component, new TransactedChangeCallback(ConnectToDataSourceCallback), null, SR.GetString(SR.ListControlDesigner_ConnectToDataSource));
}
private bool ConnectToDataSourceCallback(object context) {
ListControlConnectToDataSourceDialog dialog = new ListControlConnectToDataSourceDialog(this);
DialogResult result = UIServiceHelper.ShowDialog(Component.Site, dialog);
return (result == DialogResult.OK);
}
///
///
/// DataBinds the given control to get design time rendering
///
protected override void DataBind(BaseDataBoundControl dataBoundControl) {
// We don't need to databind here because we just added items to the items collection
return;
}
///
/// Starts collection editor for List Items
///
internal void EditItems() {
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(Component)["Items"];
Debug.Assert(descriptor != null, "Expected to find Items property on ListControl");
InvokeTransactedChange(Component, new TransactedChangeCallback(EditItemsCallback), descriptor, SR.GetString(SR.ListControlDesigner_EditItems), descriptor);
}
///
/// Transacted callback to invoke the Edit Items dialog.
///
private bool EditItemsCallback(object context) {
IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
Debug.Assert(designerHost != null);
PropertyDescriptor descriptor = (PropertyDescriptor)context;
ListItemsCollectionEditor editor = new ListItemsCollectionEditor(typeof(ListItemCollection));
editor.EditValue(new TypeDescriptorContext(designerHost, descriptor, Component),
new WindowsFormsEditorServiceHelper(this), descriptor.GetValue(Component));
return true;
}
///
///
/// Gets the HTML to be used for the design time representation of the control runtime.
///
public override string GetDesignTimeHtml() {
try {
ListControl listControl = (ListControl)ViewControl;
ListItemCollection items = listControl.Items;
bool isDataBound = IsDataBound();
if (items.Count == 0 || isDataBound) {
if (isDataBound) {
items.Clear();
items.Add(SR.GetString(SR.Sample_Databound_Text));
}
else {
items.Add(SR.GetString(SR.Sample_Unbound_Text));
}
}
return base.GetDesignTimeHtml();
}
catch (Exception e) {
return GetErrorDesignTimeHtml(e);
}
}
///
///
public IEnumerable GetResolvedSelectedDataSource() {
return ((IDataSourceProvider)this).GetResolvedSelectedDataSource();
}
///
///
public object GetSelectedDataSource() {
return ((IDataSourceProvider)this).GetSelectedDataSource();
}
///
///
///
/// Initializes the component for design.
///
///
public override void Initialize(IComponent component) {
VerifyInitializeArgument(component, typeof(ListControl));
base.Initialize(component);
}
///
///
/// Return true if the control is databound.
///
private bool IsDataBound() {
DataBinding dataSourceBinding = DataBindings["DataSource"];
return (dataSourceBinding != null || DataSourceID.Length > 0);
}
///
///
/// This method is called when the data source the control is
/// connected to changes. Override this method to perform any
/// additional actions that your designer requires. Make sure to call
/// the base implementation as well.
/// This method exists because it shipped in V1. Removing it creates a breaking change.
/// Then call the base class' implementation.
///
public virtual void OnDataSourceChanged() {
// Call the base protected implementation to inherit the default behavior
// of BaseDataBoundControlDesigner.
base.OnDataSourceChanged(true);
}
///
/// Called by data bound control designers to raise the data source
/// changed event so that listeners can be notified.
///
protected override void OnDataSourceChanged(bool forceUpdateView) {
// Call the public OnDataSourceChanged method without parameters introduced in this class,
// which exists for back-compat. This method is new in V2.
// Derived classes overrode OnDataSourceChanged(), so make sure that gets called.
this.OnDataSourceChanged();
}
///
///
///
/// Filters the properties to replace the runtime DataSource property
/// descriptor with the designer's.
///
///
protected override void PreFilterProperties(IDictionary properties) {
base.PreFilterProperties(properties);
PropertyDescriptor prop;
Attribute[] fieldPropAttrs = new Attribute[] {
new TypeConverterAttribute(typeof(DataFieldConverter))
};
prop = (PropertyDescriptor)properties["DataTextField"];
Debug.Assert(prop != null);
prop = TypeDescriptor.CreateProperty(this.GetType(), prop, fieldPropAttrs);
properties["DataTextField"] = prop;
prop = (PropertyDescriptor)properties["DataValueField"];
Debug.Assert(prop != null);
prop = TypeDescriptor.CreateProperty(this.GetType(), prop, fieldPropAttrs);
properties["DataValueField"] = prop;
}
}
}
// 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
- ObjectStateEntryDbDataRecord.cs
- TreeViewCancelEvent.cs
- EditorAttribute.cs
- MessageEncoder.cs
- baseaxisquery.cs
- AllMembershipCondition.cs
- HttpRawResponse.cs
- InheritanceContextHelper.cs
- ConfigXmlCDataSection.cs
- AvtEvent.cs
- SamlAuthorizationDecisionClaimResource.cs
- FunctionQuery.cs
- PointLightBase.cs
- GeneralEndpointIdentity.cs
- AppDomainProtocolHandler.cs
- ContentPresenter.cs
- SqlDataReader.cs
- BaseParaClient.cs
- ViewGenResults.cs
- CqlGenerator.cs
- DbProviderConfigurationHandler.cs
- SignedXml.cs
- Component.cs
- DependentList.cs
- TableItemPattern.cs
- ScriptBehaviorDescriptor.cs
- WebHttpSecurityElement.cs
- SpellCheck.cs
- MailWriter.cs
- DataGridViewComboBoxCell.cs
- DispatcherExceptionEventArgs.cs
- ReadOnlyMetadataCollection.cs
- CheckBoxFlatAdapter.cs
- SplayTreeNode.cs
- ResourceReferenceExpressionConverter.cs
- SQLCharsStorage.cs
- Bezier.cs
- GeneralTransform3DGroup.cs
- SortedList.cs
- UserPersonalizationStateInfo.cs
- TextBlock.cs
- SafeSecurityHelper.cs
- SystemIPv6InterfaceProperties.cs
- CodeSnippetCompileUnit.cs
- EditorAttributeInfo.cs
- ExpanderAutomationPeer.cs
- RemotingAttributes.cs
- TransactionChannel.cs
- OleDbErrorCollection.cs
- SHA1.cs
- Comparer.cs
- ValuePattern.cs
- DataList.cs
- ListControlStringCollectionEditor.cs
- DependencyObjectPropertyDescriptor.cs
- ObjectPropertyMapping.cs
- SendActivityDesignerTheme.cs
- bindurihelper.cs
- HttpApplicationFactory.cs
- EndpointDiscoveryMetadata.cs
- MoveSizeWinEventHandler.cs
- ToolStripSeparator.cs
- AppDomainShutdownMonitor.cs
- ListItemCollection.cs
- UserControlBuildProvider.cs
- StrongNameMembershipCondition.cs
- DelegatingMessage.cs
- AutomationPropertyInfo.cs
- DesignerSerializationOptionsAttribute.cs
- AdornerDecorator.cs
- MessageDirection.cs
- ArcSegment.cs
- TextChange.cs
- KeyEventArgs.cs
- FragmentQueryProcessor.cs
- IndexerReference.cs
- WindowsSecurityTokenAuthenticator.cs
- SafeEventLogReadHandle.cs
- RubberbandSelector.cs
- StringOutput.cs
- ExeConfigurationFileMap.cs
- PopupRootAutomationPeer.cs
- _BaseOverlappedAsyncResult.cs
- TripleDES.cs
- TextBox.cs
- Set.cs
- DecimalAnimation.cs
- TypeElement.cs
- SemanticAnalyzer.cs
- SQLMoney.cs
- BinaryParser.cs
- DefaultBinder.cs
- CryptoStream.cs
- CodePageUtils.cs
- DataGridViewSelectedColumnCollection.cs
- DelegatingTypeDescriptionProvider.cs
- ButtonField.cs
- SingleKeyFrameCollection.cs
- XAMLParseException.cs
- TableRowCollection.cs