/// <include file='doc\DataGridGeneralPage.uex' path='docs/doc[@for="DataGridGeneralPage.OnSelChangedDataMember"]/*' />
        /// <devdoc>
        ///   Handles changes in the datamember selection
        /// </devdoc>
        private void OnSelChangedDataMember(object source, EventArgs e)
        {
            if (IsLoading())
            {
                return;
            }

            string newDataMember = null;

            if (dataMemberCombo.IsSet())
            {
                newDataMember = (string)dataMemberCombo.SelectedItem;
            }

            Debug.Assert((currentDataSource != null) && (currentDataSource is ListSourceDataSourceItem));
            ListSourceDataSourceItem dsItem = (ListSourceDataSourceItem)currentDataSource;

            dsItem.CurrentDataMember = newDataMember;

            LoadDataSourceFields();
            dataSourceDirty = true;

            SetDirty();
            UpdateEnabledVisibleState();
        }
        /// <include file='doc\DataGridGeneralPage.uex' path='docs/doc[@for="DataGridGeneralPage.LoadDataSourceItems"]/*' />
        /// <devdoc>
        ///   Loads the list of available IEnumerable components
        /// </devdoc>
        private void LoadDataSourceItems()
        {
            dataSourceCombo.EnsureNotSetItem();

            ISite thisSite = GetSelectedComponent().Site;

            if (thisSite != null)
            {
                IContainer container = (IContainer)thisSite.GetService(typeof(IContainer));

                if (container != null)
                {
                    ComponentCollection allComponents = container.Components;
                    if (allComponents != null)
                    {
                        foreach (IComponent comp in (IEnumerable)allComponents)
                        {
                            if ((comp is IEnumerable) || (comp is IListSource))
                            {
                                // must have a valid site and a name
                                ISite componentSite = comp.Site;
                                if ((componentSite == null) || (componentSite.Name == null) ||
                                    (componentSite.Name.Length == 0))
                                {
                                    continue;
                                }

                                DataSourceItem dsItem;
                                if (comp is IListSource)
                                {
                                    // an IListSource
                                    IListSource listSource = (IListSource)comp;
                                    dsItem = new ListSourceDataSourceItem(componentSite.Name, listSource);
                                }
                                else
                                {
                                    // found an IEnumerable
                                    IEnumerable dataSource = (IEnumerable)comp;
                                    dsItem = new DataSourceItem(componentSite.Name, dataSource);
                                }
                                dataSourceCombo.AddItem(dsItem);
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
 private void LoadDataSourceItems()
 {
     this._cmbDataSource.EnsureNotSetItem();
     ISite site = base.GetSelectedComponent().Site;
     if (site != null)
     {
         IContainer service = (IContainer) site.GetService(typeof(IContainer));
         if (service != null)
         {
             ComponentCollection components = service.Components;
             if (components != null)
             {
                 foreach (IComponent component in components)
                 {
                     if (!(component is IEnumerable) && !(component is IListSource))
                     {
                         continue;
                     }
                     ISite site2 = component.Site;
                     if (((site2 != null) && (site2.Name != null)) && (site2.Name.Length != 0))
                     {
                         DataSourceItem item;
                         if (component is IListSource)
                         {
                             IListSource runtimeListSource = (IListSource) component;
                             item = new ListSourceDataSourceItem(site2.Name, runtimeListSource);
                         }
                         else
                         {
                             IEnumerable runtimeDataSource = (IEnumerable) component;
                             item = new DataSourceItem(site2.Name, runtimeDataSource);
                         }
                         this._cmbDataSource.AddItem(item);
                     }
                 }
             }
         }
     }
 }