/// <summary>
        /// Edits the value.
        /// </summary>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var converter = context.PropertyDescriptor.Converter;

            if (!converter.GetStandardValuesSupported(context))
            {
                throw new InvalidOperationException(Resources.StandardValuesEditor_ErrorStandardValuesUnsupported);
            }

            var windowsFormsService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            var editorControl = new NuPattern.ComponentModel.UI.StandardValuesDropDown(windowsFormsService, converter.GetStandardValues(context));

            // If the user press "Esc" we should return the original value            
            // The result variable should be updated with the result of the drop down operation
            var result = true;
            windowsFormsService.DropDownControl(editorControl);

            if (result)
            {
                var selectedValue = editorControl.SelectedValue;

                if (selectedValue != null &&
                    selectedValue.GetType() != context.PropertyDescriptor.PropertyType &&
                    converter.CanConvertFrom(context, selectedValue.GetType()))
                {
                    selectedValue = converter.ConvertFrom(context, CultureInfo.CurrentCulture, selectedValue);
                }

                return selectedValue ?? value;
            }

            return value;
        }
Example #2
0
        /// <summary>
        /// Edits the value.
        /// </summary>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var converter = context.PropertyDescriptor.Converter;

            if (!converter.GetStandardValuesSupported(context))
            {
                throw new InvalidOperationException(Resources.StandardValuesEditor_ErrorStandardValuesUnsupported);
            }

            var windowsFormsService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            var editorControl       = new NuPattern.ComponentModel.UI.StandardValuesDropDown(windowsFormsService, converter.GetStandardValues(context));

            // If the user press "Esc" we should return the original value
            // The result variable should be updated with the result of the drop down operation
            var result = true;

            windowsFormsService.DropDownControl(editorControl);

            if (result)
            {
                var selectedValue = editorControl.SelectedValue;

                if (selectedValue != null &&
                    selectedValue.GetType() != context.PropertyDescriptor.PropertyType &&
                    converter.CanConvertFrom(context, selectedValue.GetType()))
                {
                    selectedValue = converter.ConvertFrom(context, CultureInfo.CurrentCulture, selectedValue);
                }

                return(selectedValue ?? value);
            }

            return(value);
        }