/// <include file='doc\DataFieldConverter.uex' path='docs/doc[@for="DataFieldConverter.GetStandardValues"]/*' /> /// <devdoc> /// <para> /// Gets the fields present within the selected data source if information about them is available. /// </para> /// </devdoc> public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { object[] names = null; if (context != null) { ArrayList list = new ArrayList(); PropertyDescriptorCollection props = null; // REVIEW: We should try and support the multi-select scenario - Get the data source // from each selected component. If they are the same, we can proceed, // otherwise return an empty collection. // This converter shouldn't be used in a multi-select scenario. If it is, it simply // returns no standard values. IComponent component = context.Instance as IComponent; if (component != null) { ISite componentSite = component.Site; if (componentSite != null) { IDesignerHost designerHost = (IDesignerHost)componentSite.GetService(typeof(IDesignerHost)); if (designerHost != null) { IDesigner designer = designerHost.GetDesigner(component); if (designer is IDataSourceProvider) { IEnumerable dataSource = ((IDataSourceProvider)designer).GetResolvedSelectedDataSource(); if (dataSource != null) { props = DesignTimeData.GetDataFields(dataSource); } } } } } if (props != null) { foreach (PropertyDescriptor propDesc in props) { list.Add(propDesc.Name); } } names = list.ToArray(); Array.Sort(names); } return(new StandardValuesCollection(names)); }
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { object[] values = null; if (context != null) { IComponent instance = context.Instance as IComponent; if (instance != null) { ISite site = instance.Site; if (site != null) { IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost)); if (host != null) { IDesigner dataBoundControlDesigner = host.GetDesigner(instance); DesignerDataSourceView view = this.GetView(dataBoundControlDesigner); if (view != null) { IDataSourceViewSchema schema = null; try { schema = view.Schema; } catch (Exception exception) { IComponentDesignerDebugService service = (IComponentDesignerDebugService)site.GetService(typeof(IComponentDesignerDebugService)); if (service != null) { service.Fail(System.Design.SR.GetString("DataSource_DebugService_FailedCall", new object[] { "DesignerDataSourceView.Schema", exception.Message })); } } if (schema != null) { IDataSourceFieldSchema[] fields = schema.GetFields(); if (fields != null) { values = new object[fields.Length]; for (int i = 0; i < fields.Length; i++) { values[i] = fields[i].Name; } } } } if (((values == null) && (dataBoundControlDesigner != null)) && (dataBoundControlDesigner is IDataSourceProvider)) { IDataSourceProvider provider = dataBoundControlDesigner as IDataSourceProvider; IEnumerable dataSource = null; if (provider != null) { dataSource = provider.GetResolvedSelectedDataSource(); } if (dataSource != null) { PropertyDescriptorCollection dataFields = DesignTimeData.GetDataFields(dataSource); if (dataFields != null) { ArrayList list = new ArrayList(); foreach (PropertyDescriptor descriptor in dataFields) { list.Add(descriptor.Name); } values = list.ToArray(); } } } } } } } return(new TypeConverter.StandardValuesCollection(values)); }