Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / DataSourceConverter.cs / 1 / DataSourceConverter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.Design {
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
internal class DataSourceConverter : ReferenceConverter {
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public DataSourceConverter() : base(typeof(IListSource)) {
}
ReferenceConverter listConverter = new ReferenceConverter(typeof(IList));
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
ArrayList listSources = new ArrayList(base.GetStandardValues(context));
StandardValuesCollection lists = listConverter.GetStandardValues(context);
ArrayList listsList = new ArrayList();
BindingSource bs = context.Instance as BindingSource;
foreach (object listSource in listSources) {
if (listSource != null) {
// bug 46563: work around the TableMappings property on the OleDbDataAdapter
ListBindableAttribute listBindable = (ListBindableAttribute) TypeDescriptor.GetAttributes(listSource)[typeof(ListBindableAttribute)];
if (listBindable != null && !listBindable.ListBindable) {
continue;
}
// Prevent user from being able to connect a BindingSource to itself
if (bs != null && bs == listSource) {
continue;
}
// Per Whidbey spec : DataSourcePicker.doc, 3.4.1
//
// if this is a DataTable and the DataSet that owns the table is in the list,
// don't add it. this way we only show the top-level data sources and don't clutter the
// list with duplicates like:
//
// NorthWind1.Customers
// NorthWind1.Employees
// NorthWind1
//
// but instead just show "NorthWind1". This does force the user to pick a data member but helps
// with simplicity.
//
// we are doing an n^2 lookup here but this list will never be more than 10 or 15 entries long so it should
// not be a problem.
//
DataTable listSourceDataTable = listSource as DataTable;
if (listSourceDataTable == null || !listSources.Contains(listSourceDataTable.DataSet)) {
listsList.Add(listSource);
}
}
}
foreach (object list in lists) {
if (list!= null) {
// bug 46563: work around the TableMappings property on the OleDbDataAdapter
ListBindableAttribute listBindable = (ListBindableAttribute) TypeDescriptor.GetAttributes(list)[typeof(ListBindableAttribute)];
if (listBindable != null && !listBindable.ListBindable)
continue;
// Prevent user from being able to connect a BindingSource to itself
if (bs != null && bs == list) {
continue;
}
listsList.Add(list);
}
}
// bug 71417: add a null list to reset the dataSource
listsList.Add(null);
return new StandardValuesCollection(listsList);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
return true;
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
// Types are now valid data sources, so we need to be able to
// represent them as strings (since ReferenceConverter can't)
if (destinationType == typeof(string) && value is Type) {
return value.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
// 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
- IndependentlyAnimatedPropertyMetadata.cs
- TracingConnectionListener.cs
- Debug.cs
- HttpRequestCacheValidator.cs
- XmlSchemaAttribute.cs
- PropertyMapper.cs
- SqlBulkCopyColumnMappingCollection.cs
- LinkUtilities.cs
- TdsParserHelperClasses.cs
- SafeArrayRankMismatchException.cs
- EditorPartChrome.cs
- TableChangeProcessor.cs
- EntityDataSourceDataSelectionPanel.cs
- ErrorWrapper.cs
- InstanceOwnerQueryResult.cs
- ProfileParameter.cs
- CodeCommentStatementCollection.cs
- WebScriptMetadataFormatter.cs
- TextRangeEditLists.cs
- DataObjectPastingEventArgs.cs
- DataAdapter.cs
- SchemaComplexType.cs
- SqlRowUpdatingEvent.cs
- VisualCollection.cs
- WorkflowFileItem.cs
- BufferedStream2.cs
- ProfilePropertySettingsCollection.cs
- activationcontext.cs
- PathSegmentCollection.cs
- SchemaTableOptionalColumn.cs
- MessageQueuePermissionEntry.cs
- TextHidden.cs
- CompilerInfo.cs
- UpdateInfo.cs
- Point4DConverter.cs
- TreeView.cs
- NativeDirectoryServicesQueryAPIs.cs
- FilteredAttributeCollection.cs
- Page.cs
- TextPenaltyModule.cs
- ObjectListFieldsPage.cs
- GenericWebPart.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- ContextBase.cs
- SafeNativeMethodsMilCoreApi.cs
- PathGradientBrush.cs
- DataGridItemEventArgs.cs
- WebPartTransformer.cs
- HyperlinkAutomationPeer.cs
- ObjectDataSourceSelectingEventArgs.cs
- DummyDataSource.cs
- UriTemplateVariableQueryValue.cs
- ZipIOBlockManager.cs
- AssemblyAttributesGoHere.cs
- DataComponentMethodGenerator.cs
- DataGridToolTip.cs
- wgx_sdk_version.cs
- TextDataBindingHandler.cs
- Shape.cs
- CustomCredentialPolicy.cs
- RequestQueue.cs
- ComplexPropertyEntry.cs
- CodeGroup.cs
- TextParaClient.cs
- Variant.cs
- XPathNodeList.cs
- QuestionEventArgs.cs
- GlobalizationSection.cs
- DuplexSecurityProtocolFactory.cs
- CreateUserWizardAutoFormat.cs
- InputEventArgs.cs
- Int32.cs
- RuleInfoComparer.cs
- GlyphRunDrawing.cs
- ModelTreeEnumerator.cs
- BamlLocalizationDictionary.cs
- ValueUtilsSmi.cs
- FilterQueryOptionExpression.cs
- TextFormatterContext.cs
- AssociationSetMetadata.cs
- AnalyzedTree.cs
- HttpModuleAction.cs
- BlurBitmapEffect.cs
- CompilerError.cs
- AesManaged.cs
- _emptywebproxy.cs
- ParentQuery.cs
- KnownTypeHelper.cs
- XMLUtil.cs
- PathGradientBrush.cs
- WindowsPrincipal.cs
- SqlClientMetaDataCollectionNames.cs
- RepeaterItemCollection.cs
- HttpCachePolicy.cs
- RuleProcessor.cs
- Grid.cs
- NavigationProperty.cs
- TableCellAutomationPeer.cs
- AspNetRouteServiceHttpHandler.cs
- GridItemPattern.cs