Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 78072

RadMaskedEditBox with nullable value

$
0
0

Hi,

 

It has been a while since I asked the question above, but thank you for your prompt reply.  I am developing another program where I need another control for currency, but I need to be binded to a nullable decimal property.  I've inherited from your RadMaskedEditBox control and was able to make it work, but I have 2 outstanding issues.

 

1. I used your suggestion above to handle Parse event of Binding object to handle null values.  But is it possible to integrate this into my control so that I don't have to worry about handling this property each time I bind this control.

2. When user selects the whole text and presses delete, I would like for the Value to be set to 0.  But it seems like $0.00 is always substituted there. 

Please take a look at my code below and let me know what else I can do to handle 2 situations above.

 

usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Globalization;
usingSystem.Linq;
usingSystem.Text;
usingTelerik.WinControls.Analytics;
usingTelerik.WinControls.UI;
 
namespaceAllergyCanada.WinControls.UI
{
    publicclassMidexCurrencyEditBox : RadMaskedEditBox
    {
        publicMidexCurrencyEditBox() : base()
        {
            MaskType = Telerik.WinControls.UI.MaskType.Numeric;
            Mask = "C2";
            TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            MidexCurrencyEditBox radMaskedEditBox = this;
            base.ValueChanged += newEventHandler(radMaskedEditBox.OnCurrencyValueChanged);
            MidexCurrencyEditBox radMaskedEditBox1 = this;
            base.ValueChanging += newCancelEventHandler(radMaskedEditBox1.OnCurrencyValueChanging);
        }      
 
 
        protectedoverridevoidDispose(booldisposing)
        {
            MidexCurrencyEditBox radMaskedEditBox = this;
            base.ValueChanged -= newEventHandler(radMaskedEditBox.OnCurrencyValueChanged);
            MidexCurrencyEditBox radMaskedEditBox1 = this;
            base.ValueChanging -= newCancelEventHandler(radMaskedEditBox1.OnCurrencyValueChanging);
            base.Dispose(disposing);
        }
 
 
        [Bindable(true)]
        [Browsable(true)]
        [Category("Behavior")]
        [DefaultValue("")]
        [Description("Gets or sets the value associated to the mask edit box")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        publicdecimal? CurrencyValue
        {
            get
            {
                if(base.MaskedEditBoxElement.Value == null)
                    returnnull;
 
                returndecimal.Parse(base.MaskedEditBoxElement.Value.ToString(), NumberStyles.Currency);
            }
            set
            {
                base.MaskedEditBoxElement.Value = value;
                OnNotifyPropertyChanged("CurrencyValue");
            }
        }
 
        /// <summary>
        /// Occurs when the editing value has been changed
        /// </summary>
        [Category("Action")]
        [Description("Occurs when the editing currency value has been changed")]
        publiceventEventHandler CurrencyValueChanged;
 
 
        /// <summary>
        /// Occurs when the editing value is changing.
        /// </summary>
        [Category("Action")]
        [Description(" Occurs when the editing currency value is changing.")]
        publiceventCancelEventHandler CurrencyValueChanging;
 
 
        protectedvirtualvoidOnCurrencyValueChanged(objectsender, EventArgs e)
        {
            this.CurrencyValueChanged?.Invoke(this, e);
            this.OnNotifyPropertyChanged("CurrencyValue");
            ControlTraceMonitor.TrackAtomicFeature(this, "CurrencyValueChanged", this.Text);
        }
 
        /// <summary>
        /// Fires the ValueChanging event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protectedvirtualvoidOnCurrencyValueChanging(objectsender, CancelEventArgs e)
        {
            this.CurrencyValueChanging?.Invoke(this, e);
        }
 
    }
}

Viewing all articles
Browse latest Browse all 78072

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>