public virtual TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context, Type typeFilter)
 {
     string[] destinationArray = null;
     if (context != null)
     {
         IDataSourceViewSchemaAccessor instance = context.Instance as IDataSourceViewSchemaAccessor;
         if (instance != null)
         {
             IDataSourceViewSchema dataSourceViewSchema = instance.DataSourceViewSchema as IDataSourceViewSchema;
             if (dataSourceViewSchema != null)
             {
                 IDataSourceFieldSchema[] fields = dataSourceViewSchema.GetFields();
                 string[] sourceArray            = new string[fields.Length];
                 int      index = 0;
                 for (int i = 0; i < fields.Length; i++)
                 {
                     if (((typeFilter != null) && (fields[i].DataType == typeFilter)) || (typeFilter == null))
                     {
                         sourceArray[index] = fields[i].Name;
                         index++;
                     }
                 }
                 destinationArray = new string[index];
                 Array.Copy(sourceArray, destinationArray, index);
             }
         }
         if (destinationArray == null)
         {
             destinationArray = new string[0];
         }
         Array.Sort(destinationArray, Comparer.Default);
     }
     return(new TypeConverter.StandardValuesCollection(destinationArray));
 }
 private void PopulateSchemaRecursive(System.Windows.Forms.TreeNodeCollection nodes, IDataSourceViewSchema viewSchema, int depth, IDictionary duplicates)
 {
     if (viewSchema != null)
     {
         SchemaTreeNode node = new SchemaTreeNode(viewSchema);
         nodes.Add(node);
         SchemaTreeNode node2 = (SchemaTreeNode)duplicates[viewSchema.Name];
         if (node2 != null)
         {
             node2.Duplicate = true;
             node.Duplicate  = true;
         }
         foreach (TreeNodeBinding binding in this._bindingsListView.Items)
         {
             if (string.Compare(binding.DataMember, viewSchema.Name, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 IDataSourceViewSchemaAccessor accessor = binding;
                 if ((depth == binding.Depth) || (accessor.DataSourceViewSchema == null))
                 {
                     accessor.DataSourceViewSchema = viewSchema;
                 }
             }
         }
         IDataSourceViewSchema[] children = viewSchema.GetChildren();
         if (children != null)
         {
             for (int i = 0; i < children.Length; i++)
             {
                 this.PopulateSchemaRecursive(node.Nodes, children[i], depth + 1, duplicates);
             }
         }
     }
 }
コード例 #3
0
 private string[] GetControlDataFieldNames()
 {
     if (this._dataFields == null)
     {
         ITypeDescriptorContext   context = this.editor.Context;
         IDataSourceFieldSchema[] fields  = null;
         IDataSourceViewSchema    dataSourceViewSchema = null;
         if ((context != null) && (context.Instance != null))
         {
             System.Web.UI.Control instance = context.Instance as System.Web.UI.Control;
             if (instance != null)
             {
                 ISite site = instance.Site;
                 if (site != null)
                 {
                     IDesignerHost host = (IDesignerHost)site.GetService(typeof(IDesignerHost));
                     if (host != null)
                     {
                         DataBoundControlDesigner designer = host.GetDesigner(instance) as DataBoundControlDesigner;
                         if (designer != null)
                         {
                             DesignerDataSourceView designerView = designer.DesignerView;
                             if (designerView != null)
                             {
                                 try
                                 {
                                     dataSourceViewSchema = designerView.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 }));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             else
             {
                 IDataSourceViewSchemaAccessor accessor = context.Instance as IDataSourceViewSchemaAccessor;
                 if (accessor != null)
                 {
                     dataSourceViewSchema = accessor.DataSourceViewSchema as IDataSourceViewSchema;
                 }
             }
         }
         if (dataSourceViewSchema != null)
         {
             fields = dataSourceViewSchema.GetFields();
             if (fields != null)
             {
                 int length = fields.Length;
                 this._dataFields = new string[length];
                 for (int i = 0; i < length; i++)
                 {
                     this._dataFields[i] = fields[i].Name;
                 }
             }
         }
     }
     return(this._dataFields);
 }