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.
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Globalization;
using
System.Linq;
using
System.Text;
using
Telerik.WinControls.Analytics;
using
Telerik.WinControls.UI;
namespace
AllergyCanada.WinControls.UI
{
public
class
MidexCurrencyEditBox : RadMaskedEditBox
{
public
MidexCurrencyEditBox() :
base
()
{
MaskType = Telerik.WinControls.UI.MaskType.Numeric;
Mask =
"C2"
;
TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
MidexCurrencyEditBox radMaskedEditBox =
this
;
base
.ValueChanged +=
new
EventHandler(radMaskedEditBox.OnCurrencyValueChanged);
MidexCurrencyEditBox radMaskedEditBox1 =
this
;
base
.ValueChanging +=
new
CancelEventHandler(radMaskedEditBox1.OnCurrencyValueChanging);
}
protected
override
void
Dispose(
bool
disposing)
{
MidexCurrencyEditBox radMaskedEditBox =
this
;
base
.ValueChanged -=
new
EventHandler(radMaskedEditBox.OnCurrencyValueChanged);
MidexCurrencyEditBox radMaskedEditBox1 =
this
;
base
.ValueChanging -=
new
CancelEventHandler(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)]
public
decimal
? CurrencyValue
{
get
{
if
(
base
.MaskedEditBoxElement.Value ==
null
)
return
null
;
return
decimal
.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"
)]
public
event
EventHandler CurrencyValueChanged;
/// <summary>
/// Occurs when the editing value is changing.
/// </summary>
[Category(
"Action"
)]
[Description(
" Occurs when the editing currency value is changing."
)]
public
event
CancelEventHandler CurrencyValueChanging;
protected
virtual
void
OnCurrencyValueChanged(
object
sender, 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>
protected
virtual
void
OnCurrencyValueChanging(
object
sender, CancelEventArgs e)
{
this
.CurrencyValueChanging?.Invoke(
this
, e);
}
}
}