コード例 #1
0
        /// <include file='doc\DesignTimeData.uex' path='docs/doc[@for="DesignTimeData.GetSelectedDataSource1"]/*' />
        /// <devdoc>
        /// </devdoc>
        public static IEnumerable GetSelectedDataSource(IComponent component, string dataSource, string dataMember)
        {
            IEnumerable selectedDataSource = null;

            object selectedDataSourceObject = DesignTimeData.GetSelectedDataSource(component, dataSource);

            if (selectedDataSourceObject != null)
            {
                IListSource listSource = selectedDataSourceObject as IListSource;
                if (listSource != null)
                {
                    if (listSource.ContainsListCollection == false)
                    {
                        // the returned list is itself the list we want to bind to
                        selectedDataSource = (IEnumerable)listSource.GetList();
                    }
                    else
                    {
                        selectedDataSource = GetDataMember(listSource, dataMember);
                    }
                }
                else
                {
                    Debug.Assert(selectedDataSourceObject is IEnumerable);
                    selectedDataSource = (IEnumerable)selectedDataSourceObject;
                }
            }

            return(selectedDataSource);
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
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));
 }
コード例 #4
0
        /// <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));
        }
コード例 #5
0
 public virtual IEnumerable GetDesignTimeData(int minimumRows, out bool isSampleData)
 {
     isSampleData = true;
     return(DesignTimeData.GetDesignTimeDataSource(DesignTimeData.CreateDummyDataBoundDataTable(), minimumRows));
 }
コード例 #6
0
 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));
 }