Completed
Last Updated: 11 Nov 2016 09:19 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 12 Jan 2015 08:42
Category:
Type: Bug Report
0
FIX. RadDataEntry - Property value is reset when the editor is RadMaskedEditBox and the property is Nullable<int>
To reproduce: use the following code:

public Form1()
{
    InitializeComponent();
   
    this.radDataEntry1.DataSource = new Employee()
    {
        FirstName = "Sarah",
        LastName = "Blake",
        Salary = null,
    };
}

private class Employee
{
    public string FirstName { get; set; }

    public string LastName { get; set; }

    public Nullable<int> Salary { get; set; }
}

private void radDataEntry1_EditorInitializing(object sender, EditorInitializingEventArgs e)
{
    if (e.Property.Name == "Salary")
    {
        RadMaskedEditBox radMaskedEditBox = new RadMaskedEditBox();
        radMaskedEditBox.MaskType = MaskType.Numeric;
        radMaskedEditBox.Mask = "c";
        radMaskedEditBox.NullText = "$0.00";
        radMaskedEditBox.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
        radMaskedEditBox.MaskedEditBoxElement.StretchVertically = true;
        e.Editor = radMaskedEditBox;
    }
}

private void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
{
    if (e.DataMember == "Salary")
    {
        e.Binding.Parse += new ConvertEventHandler(Binding_Parse);
    }
}

void Binding_Parse(object sender, ConvertEventArgs e)
{
    Nullable<int> salary = int.Parse(e.Value.ToString(), NumberStyles.Currency);
    e.Value = salary;
}

1. Focus the RadMaskedEditBox.
2. Enter some value and press Tab key.
3. The value will be reset to its initial state.

Workaround:

public class CustomRadDataEntry : RadDataEntry
{
    public override string ThemeClassName  
    { 
        get 
        { 
            return typeof(RadDataEntry).FullName;  
        }
    }

    protected override RadScrollablePanelElement CreatePanelElement()
    {
        return new CustomRadDataEntryElement();
    }
}

public class CustomRadDataEntryElement:RadDataEntryElement
{
    protected override Type ThemeEffectiveType     
    { 
        get    
        { 
            return typeof(RadDataEntryElement);     
        }
    }

    protected override Binding CreateBinding(Control control, string propertyName, string dataMember)
    {
        Binding binding = null;
        object bindObject = null;

        if (this.Manager is CurrencyManager)
        {
            bindObject = (this.Manager as CurrencyManager).List;
        }
        else
        {
            bindObject = this.Manager.Current;
        }
        BindingCreatingEventArgs args = new BindingCreatingEventArgs(control, propertyName, bindObject, dataMember);
        OnBindingCreating(this, args);

        if (args.Cancel)
        {
            return binding;
        }

        binding = new Binding(args.PropertyName, bindObject, args.DataMember, true, DataSourceUpdateMode.OnPropertyChanged);

        OnBindingCreated(this, new BindingCreatedEventArgs(control, args.PropertyName, bindObject, args.DataMember, binding));

        return binding;
    }
}

Resolution: 
You need to subscribe to the BindingCreating event and set the FormattingEnabled property to true. Here is the code snippet: 
void radDataEntry1_BindingCreating(object sender, BindingCreatingEventArgs e)
{
    if (e.DataMember == "Salary")
    {
        e.FormattingEnabled = true;
    }
} 
0 comments