//- realy on SurfaceManager.ActiveDesignSurface
    //- which effectively points to ACTIVE DesignSurface
    public void ReloadComboBox() {
        _bSuppressEvents = true;
        try {
            //- IDesignerEventService provides a global eventing mechanism for designer events. With this mechanism,
            //- an application is informed when a designer becomes active. The service provides a collection of
            //- designers and a single place where global objects, such as the Properties window, can monitor selection
            //- change events.
            IDesignerEventService des = (IDesignerEventService) SurfaceManager.GetService( typeof( IDesignerEventService ) );
            if( null == des )
                return;
            IDesignerHost host = des.ActiveDesigner;


            object selectedObj = pgrdPropertyGrid.SelectedObject;
            if( null == selectedObj )
                return; //- don't reload at all


            //- get the name of the control selected from the comboBox
            //- and if we are not able to get it then it's better to exit
            string sName = string.Empty;
            if( selectedObj is Form ) {
                sName = ((Form) selectedObj).Name;
            }
            else if( selectedObj is Control ) {
                sName = ((Control) selectedObj).Site.Name;
            }
            if( string.IsNullOrEmpty( sName ) )
                return;



            //- prepare the data for reloading the combobox (begin)
            List<object> ctrlsToAdd = new List<object>();
            string pgrdComboBox_Text = string.Empty;
            try {
                ComponentCollection ctrlsExisting = host.Container.Components;
                Debug.Assert( 0 != ctrlsExisting.Count );


                foreach( Component comp in ctrlsExisting ) {
                    string sItemText = TranslateComponentToName( comp );
                    ctrlsToAdd.Add( sItemText );
                    if( sName == comp.Site.Name )
                        pgrdComboBox_Text = sItemText;
                }//end_foreach
            }
            catch( Exception ) {
                return; //- (rollback)
            }
            //- update the combobox (commit)
            pgrdComboBox.Items.Clear();
            pgrdComboBox.Items.AddRange( ctrlsToAdd.ToArray() );
            pgrdComboBox.Text = pgrdComboBox_Text;
        }
        finally {
            _bSuppressEvents = false;
        }
    }
Beispiel #2
0
        //- rely on SurfaceManager.ActiveDesignSurface
        //- which effectively points to ACTIVE DesignSurface
        private void OrientPropertyGridTowardsObject()
        {
            //- IDesignerEventService provides a global eventing mechanism for designer events. With this mechanism,
            //- an application is informed when a designer becomes active. The service provides a collection of
            //- designers and a single place where global objects, such as the Properties window, can monitor selection
            //- change events.
            IDesignerEventService des = (IDesignerEventService)SurfaceManager.GetService(typeof(IDesignerEventService));

            if (null == des)
            {
                return;
            }
            IDesignerHost host = des.ActiveDesigner;

            //- get the ISelectionService from the active Designsurface
            //- and if we are not able to get it then it'sType better to exit
            ISelectionService iSel = host.GetService(typeof(ISelectionService)) as ISelectionService;

            if (iSel == null)
            {
                return;
            }

            //- get the name of the control selected from the comboBox
            //- and if we are not able to get it then it's better to exit
            string sName = pgrdComboBox.SelectedItem.ToString();

            if (string.IsNullOrEmpty(sName))
            {
                return;
            }

            //- save the collection of objects currently selected

            //- loop through the controls inside the current Designsurface
            //- if we find the one selected into the comboBox then
            //- use the ISelectionService to select it
            //- (and this will select it into the PropertyGridHost)
            ComponentCollection ctrlsExisting = host.Container.Components;

            Debug.Assert(0 != ctrlsExisting.Count);
            foreach (Component comp in ctrlsExisting)
            {
                string sItemText = TranslateComponentToName(comp);
                if (sName == sItemText)
                {
                    Component[] arr = { comp };
                    //- ISelectionService in action...
                    iSel.SetSelectedComponents(arr);
                    //this.SelectedObject = arr[0];
                    break;
                }
            }
        }