Cannot set property to readonly when using custom editor

Hello Support,

I wanted to set a readonly double field to have 4 decimal places so I've followed examples to use a custom editor. However when the custom editor is applied the readonly attribute is not applied.

Here is a sample of my code:

Snippet
[Editor(typeof(double), typeof(DoubleNumberEditor))]
public struct LevelSet
{
    [ReadOnly(true)]
    public double VIH { getset; }
}
Snippet
public class DoubleNumberEditor : DoubleTextBoxEditor
{
    DoubleTextBox _doubleTextBox;
 
    public override void Attach(PropertyViewItem property, PropertyItem info)
    {
        if (info.CanWrite)
        {
            var binding = new Binding("Value")
            {
                Mode = BindingMode.TwoWay,
                Source = info,
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true
            };
          BindingOperations.SetBinding(_doubleTextBox, DoubleTextBox.ValueProperty, binding);
        }
        else
        {
            var binding = new Binding("Value")
            {
                Source = info,
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true
            };
          BindingOperations.SetBinding(_doubleTextBox, DoubleTextBox.ValueProperty, binding);
        }
    }
    public override object Create(PropertyInfo propertyInfo)     {         _doubleTextBox = new DoubleTextBox()         {             GroupSeperatorEnabled = false,             NumberDecimalDigits = 4,         };         return _doubleTextBox;     } }

Could you show me how to make the custom editor for the double text property be readonly?

Thanks,

Alan


7 Replies

SN Sudharsan Narayanan Syncfusion Team July 14, 2021 07:28 AM UTC

Hi Alan,

Thanks for contacting syncfusion support,

We have checked the reported query from our end. We can be able to set the read only property and prepare the sample for the reference in given below location.

Sample: https://www.syncfusion.com/downloads/support/forum/167190/ze/CustomEditor_(2)152978676

Please ensure our sample and let us know our procedure is same as yours if not please share the issue reproducing project file and the video for the same. It will be helpful for us to proceed further and provide a prompt solution on this.

Regards,
Sudharsan



AK Alan Kin July 14, 2021 12:56 PM UTC

Hi Sudharsan,

Thanks for the sample, however it does not demonstrate the problem I have: the Employee model is not using the custom editor "DoubleNumberEditor"; I want to have a readonly property of double type, with 4 decimal places.

For example, if I add this new property to the Employee model:

Snippet
[ReadOnly(true)]
[Editor(typeof(double), typeof(DoubleNumberEditor))]
public double NumKids
{
    get;
    set;
}

I get the following output:


As you can see the NumKids property using the custom editor is still enabled.

Thanks,

Alan



SN Sudharsan Narayanan Syncfusion Team July 15, 2021 08:06 AM UTC

Hi Alan,

Thanks for update,

We have checked the reported issue that “ReadOnly when using CustomEditor” from our end and to achieve the requirement. We have prepared the sample for the reference in given below location.

Sample: https://www.syncfusion.com/downloads/support/forum/167190/ze/CustomEditor1503055742




Regards, 
Sudharsan 



AK Alan Kin July 15, 2021 01:16 PM UTC

Hello,

In your sample it is not using the custom editor for the doubles type.  What I'm looking for is a doubles property with 4 decimal places AND is readonly.  Once you update the ViewModel to the following, the ReadOnly(true) attribute on the NumKids property is not applied:

Snippet
public ViewModel()
{    SelectedEmployee = new Employee() { Age = 25, Name = "mark", Experience = 5, EmailID = "mark@gt",NumKids=9135 };
    CustomEditor editor = new CustomEditor();
    editor.Editor = new DoubleNumberEditor();
    editor.HasPropertyType = true;
    editor.PropertyType = typeof(double);
    CustomEditorCollection.Add(editor);
}


SN Sudharsan Narayanan Syncfusion Team July 16, 2021 06:45 AM UTC

Hi Alan,

Thanks for the update,

From our end, we have checked the reported issue that “custom editor ReadOnly not applied for the property”. As you’re using the custom editor, we may change the editor control needs by using the attach, create method. So, We have modified the sample to achieve the requirement. Please check the sample and documentation from the below location,

Sample: https://www.syncfusion.com/downloads/support/forum/167190/ze/CustomEditor_DoubleTextBox541058999

Documentation: https://help.syncfusion.com/wpf/propertygrid/customeditor-support

 
Regards,  
Sudharsan


AK Alan Kin July 16, 2021 02:45 PM UTC

Thank you this is just what I needed.


Regards,

Alan



SN Sudharsan Narayanan Syncfusion Team July 19, 2021 04:15 AM UTC

Hi Alan,

 
Thanks for the update.

 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,
Sudharsan
 


Loader.
Up arrow icon