CustomComboBoxEditor of PropertyGrid

Posted by: info on 4 September 2023, 3:02 pm EST

    • Post Options:
    • Link

    Posted 4 September 2023, 3:02 pm EST

    Hello.

    In the previous PropertyGrid, the CustomComboBoxEditor was the following code:

    
    public class CustomComboBoxEditor : C1ComboBox, ITypeEditorControl
    {
        // Events
        public event PropertyChangedEventHandler ValueChanged;
    
        // Fields
        internal PropertyAttribute _selectedProperty;
        private List<String> _itemsSource;
    
        // Implementation
        public CustomComboBoxEditor(List<String> itemsSource)
        {
            _itemsSource = itemsSource;
        }
    
        public ITypeEditorControl Create()
        {
            return new CustomComboBoxEditor(_itemsSource);
        }
    
        public void Attach(PropertyAttribute property)
        {
            EditorTypes editorType = EditorTypes.Align;
            string selectedItemSelectedValueString;
    
            //if (property.MemberName == "PictureScale")
            //{
            //    editorType = EditorTypes.PictureScale;
            //    selectedItemSelectedValueString = (property.SelectedObject as FlexImage).PictureScale;
            //}
            //else
            //{
            editorType = EditorTypes.Align;
            selectedItemSelectedValueString = (property.SelectedObject as FlexTextBox).Align;
            //}
            // Store current property
            _selectedProperty = property;
    
            // Set ComboBox
            this.ItemsSource = _itemsSource;
            this.SelectedItemChanged += CustomEditor_SelectedItemChanged;
    
            // Bind Property to SelectedItem
            Binding editorBinding = new Binding(property.MemberName);
            editorBinding.Mode = BindingMode.TwoWay;
            editorBinding.Source = property.SelectedObject;
            this.SetBinding(C1ComboBox.SelectedItemProperty, editorBinding);
    
            if (this.SelectedItem == null)
            {
                switch (editorType)
                {
                    case EditorTypes.Align:
                        (property.SelectedObject as FlexTextBox).Align = selectedItemSelectedValueString;
                        break;
                    //case EditorTypes.PictureScale:
                    //    (property.SelectedObject as FlexImage).PictureScale = selectedItemSelectedValueString;
                    //    break;
                    default:
                        break;
                }
    
            }
        }
    
        public void Detach(PropertyAttribute property)
        {
            this.SelectedItemChanged -= CustomEditor_SelectedItemChanged;
        }
    
        public bool Supports(PropertyAttribute Property)
        {
            return Property.PropertyInfo.PropertyType == typeof(string);
        }
    
        private void CustomEditor_SelectedItemChanged(object sender, PropertyChangedEventArgs<object> e)
        {
            if (ValueChanged != null)
                ValueChanged(this, new PropertyChangedEventArgs(_selectedProperty.MemberName));
        }
    
        private enum EditorTypes
        {
            Align,
            //PictureScale
        }
    }
    

    I have to port this.

    Could you please create a CustomComboBox sample for PropertyGrid in 2023 v2?

  • Posted 5 September 2023, 10:49 pm EST

    Hi Mikihiro,

    ITypeEditorControl has been replaced by IPropertyGridEditor interface in C1PropertyGrid 2023v2 release. You can refer here for more information regarding the same: https://www.grapecity.com/componentone/docs/wpf/online-releasehistory/2023%20v2.html

    Therefore, you have to modify the CustomComboBoxEditor class accordingly. We are hereby providing you with the updated code snippet as per our understanding:

    public class CustomComboBoxEditor : C1ComboBox, IPropertyGridEditor
    {
        // Events
        public event PropertyChangedEventHandler ValueChanged;
        // Fields
        internal PropertyAttribute _selectedProperty;
        private List<String> _itemsSource;
        // Implementation
        public CustomComboBoxEditor(List<String> itemsSource)
        {
            _itemsSource = itemsSource;
        }
        public void Attach(FrameworkElement editor, PropertyGroup group, Action<FrameworkElement, object
        {
            EditorTypes editorType = EditorTypes.Align;
            string selectedItemSelectedValueString;
            editorType = EditorTypes.Align;
            selectedItemSelectedValueString = (group.Properties[0].SelectedObject as FlexTextBox).Align;
            //}
            // Store current property
            _selectedProperty = group.Properties[0];
            // Set ComboBox
            this.ItemsSource = _itemsSource;
            this.SelectedItemChanged += CustomEditor_SelectedItemChanged;
            // Bind Property to SelectedItem
            Binding editorBinding = new Binding(group.Properties[0].MemberName);
            editorBinding.Mode = BindingMode.TwoWay;
            editorBinding.Source = group.Properties[0].SelectedObject;
            this.SetBinding(C1ComboBox.SelectedItemProperty, editorBinding);
            if (this.SelectedItem == null)
            {
                switch (editorType)
                {
                    case EditorTypes.Align:
                        (group.Properties[0].SelectedObject as FlexTextBox).Align = selectedItemSelected
                        break;
                    //case EditorTypes.PictureScale:
                    //    (property.SelectedObject as FlexImage).PictureScale = selectedItemSelectedValu
                    //    break;
                    default:
                        break;
                }
            }
        }
        public FrameworkElement Create(C1PropertyGrid parent)
        {
            return new CustomComboBoxEditor(_itemsSource);
        }
        public void Detach(FrameworkElement editor)
        {
            this.SelectedItemChanged -= CustomEditor_SelectedItemChanged;
        }
        public bool Supports(PropertyInfo property)
        {
            return property.PropertyType == typeof(string);
        }
        private void CustomEditor_SelectedItemChanged(object sender, PropertyChangedEventArgs<object> e)
        {
            if (ValueChanged != null)
                ValueChanged(this, new PropertyChangedEventArgs(_selectedProperty.MemberName));
        }
        private enum EditorTypes
        {
            Align,
            //PictureScale
        }
    }

    In case you still face issues regarding this, we request you provide us with the stripped-down version of your sample application (that you want to update), so that we can understand the implementation at your end and provide you with a solution accordingly.

    Thanks & Regards,

    Aastha

  • Posted 14 September 2023, 9:08 pm EST

    Thank you for your help.

    I created a CustomComboBoxEditor halfway by referring to the sample code of PropertyGridExplorer.

    I am unable to create Attach, Detach methods properly.

    Could you please complete it?

    20230915PropertyGridStudy.zip

  • Posted 18 September 2023, 4:00 am EST

    Hi Mikihiro,

    We are currently working on this issue. We appreciate your patience while we work towards finding a way to achieve the desired behavior.

    Thanks & Regards,

    Aastha

  • Posted 19 September 2023, 11:59 am EST

    Hi Mikihiro,

    As per our analysis from the code snippet you provided earlier and the attached sample application, it seems that you are facing an issue while creating handlers for your custom C1ComboBox editor in its Attach method.

    We have updated your sample application by implementing this requirement. Please check PropertyGridStudy_Mod.zip.

    In case you still have any issues, please let us know what exactly you want to achieve through your custom C1ComboBox editor in detail. This will help us understand what you want to achieve through your Attach and Detach method so that we could assist you accordingly. Furthermore, you can refer to the following link for more information regarding the WPF C1PropertyGrid Editors: https://www.grapecity.com/componentone/docs/wpf/online-propertygrid/editors.html

    Thanks & Regards,

    Aastha

  • Posted 28 September 2023, 4:05 pm EST

    Thank you for the sample.

    I was able to implement the required functionality using the sample.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels