Exemplo n.º 1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (null == provider)
            {
                Debug.Assert(false, "NoneOptionListBoxTypeEditor.EditValue(): provider object must not be null");
                // returning value means "no change"
                return(value);
            }
            else
            {
                _editorService =
                    provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                Debug.Assert(null != _editorService, "Could not find IWindowsFormsEditorService for provider " + provider);
                if (null != _editorService)
                {
                    // create and populate the list-box
                    using (var listBox = new NoneOptionListBox())
                    {
                        // if the (None) value was the incoming value then show this by pre-selecting that
                        // value in the list, otherwise leave all items unselected
                        if (StringOrNone.NoneValue.Equals(value))
                        {
                            listBox.SelectedIndex = 0;
                        }

                        // now set up the SelectedValueChanged event handler
                        listBox.SelectedValueChanged += listBox_SelectedValueChanged;

                        // display the list-box and let user choose
                        _editorService.DropDownControl(listBox);
                        var selectedItem = listBox.SelectedItem as string;
                        Debug.Assert(
                            null == selectedItem ||
                            Resources.NoneDisplayValueUsedForUX.Equals(selectedItem, StringComparison.CurrentCulture),
                            typeof(NoneOptionListBox).Name + ": selectedItem should be null or NoneObject");

                        // desubscribe from the SelectedValueChanged event handler
                        listBox.SelectedValueChanged -= listBox_SelectedValueChanged;

                        // return value dependent on what user chose
                        if (Resources.NoneDisplayValueUsedForUX.Equals(selectedItem, StringComparison.CurrentCulture))
                        {
                            value = StringOrNone.NoneValue;
                        }
                        else
                        {
                            // user did not select the None option - return null indicating no selection
                            value = null;
                        }
                    }
                }
            }

            return(value);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (null == provider)
            {
                Debug.Assert(false, "NoneOptionListBoxTypeEditor.EditValue(): provider object must not be null");
                // returning value means "no change"
                return value;
            }
            else
            {
                _editorService =
                    provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                Debug.Assert(null != _editorService, "Could not find IWindowsFormsEditorService for provider " + provider);
                if (null != _editorService)
                {
                    // create and populate the list-box
                    using (var listBox = new NoneOptionListBox())
                    {
                        // if the (None) value was the incoming value then show this by pre-selecting that
                        // value in the list, otherwise leave all items unselected
                        if (StringOrNone.NoneValue.Equals(value))
                        {
                            listBox.SelectedIndex = 0;
                        }

                        // now set up the SelectedValueChanged event handler
                        listBox.SelectedValueChanged += listBox_SelectedValueChanged;

                        // display the list-box and let user choose
                        _editorService.DropDownControl(listBox);
                        var selectedItem = listBox.SelectedItem as string;
                        Debug.Assert(
                            null == selectedItem
                            || Resources.NoneDisplayValueUsedForUX.Equals(selectedItem, StringComparison.CurrentCulture),
                            typeof(NoneOptionListBox).Name + ": selectedItem should be null or NoneObject");

                        // desubscribe from the SelectedValueChanged event handler
                        listBox.SelectedValueChanged -= listBox_SelectedValueChanged;

                        // return value dependent on what user chose
                        if (Resources.NoneDisplayValueUsedForUX.Equals(selectedItem, StringComparison.CurrentCulture))
                        {
                            value = StringOrNone.NoneValue;
                        }
                        else
                        {
                            // user did not select the None option - return null indicating no selection
                            value = null;
                        }
                    }
                }
            }

            return value;
        }