示例#1
0
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     string[] array = null;
     if (context != null)
     {
         IComponent instance = context.Instance as IComponent;
         if (instance != null)
         {
             ISite site = instance.Site;
             if (site != null)
             {
                 IDesignerHost service = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                 if (service != null)
                 {
                     IDesigner dataBoundControlDesigner = service.GetDesigner(instance);
                     DesignerDataSourceView view        = this.GetView(dataBoundControlDesigner);
                     if (view != null)
                     {
                         IDataSourceDesigner dataSourceDesigner = view.DataSourceDesigner;
                         if (dataSourceDesigner != null)
                         {
                             string[] viewNames = dataSourceDesigner.GetViewNames();
                             if (viewNames != null)
                             {
                                 array = new string[viewNames.Length];
                                 viewNames.CopyTo(array, 0);
                             }
                         }
                     }
                     if (((array == null) && (dataBoundControlDesigner != null)) && (dataBoundControlDesigner is IDataSourceProvider))
                     {
                         IDataSourceProvider provider = dataBoundControlDesigner as IDataSourceProvider;
                         object dataSource            = null;
                         if (provider != null)
                         {
                             dataSource = provider.GetSelectedDataSource();
                         }
                         if (dataSource != null)
                         {
                             array = DesignTimeData.GetDataMembers(dataSource);
                         }
                     }
                 }
             }
         }
         if (array == null)
         {
             array = new string[0];
         }
         Array.Sort(array, Comparer.Default);
     }
     return(new TypeConverter.StandardValuesCollection(array));
 }
        /// <include file='doc\DataMemberConverter.uex' path='docs/doc[@for="DataMemberConverter.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)
        {
            string[] names = null;

            if (context != 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)
                            {
                                object dataSource = ((IDataSourceProvider)designer).GetSelectedDataSource();

                                if (dataSource != null)
                                {
                                    names = DesignTimeData.GetDataMembers(dataSource);
                                }
                            }
                        }
                    }
                }

                if (names == null)
                {
                    names = new string[0];
                }
                Array.Sort(names);
            }
            return(new StandardValuesCollection(names));
        }