This is a migrated thread and some comments may be shown as answers.

RadCalculatorDropdown Value with 2 decimal digits

2 Answers 177 Views
CalculatorDropDown
This is a migrated thread and some comments may be shown as answers.
Agung
Top achievements
Rank 1
Agung asked on 11 Sep 2018, 06:16 PM

Hi,

How to assign RadCalculatorDropdown.Value always with number decimal digit each equals button click.

for example:

i have input 22 / 7

but result is 3,1428571428571428571428571429

i want the result is 3,1429 with 4 digit decimal

thanks

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Sep 2018, 11:41 AM
Hello, Agung,          

RadCalculatorEditorContentElement is a derivative of the RadTextBoxElement which hosts the standard MS TextBox. It does not offer formatting out of the box. Additionally, the RadCalculatorDropDownElement.Value property accepts decimal values. Hence, in order to force some custom format to the calculator, you can use a RadMaskedEditBox and add the arrow button that shows the calculator popup. Here is a sample implementation: 

RadCalculatorDropDownElement calculatorElement = new RadCalculatorDropDownElement();
 
public RadForm1()
{
    InitializeComponent();
      
    this.radMaskedEditBox1.MaskType = MaskType.Numeric;
    this.radMaskedEditBox1.Mask = "N4";
    CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture.Clone() as CultureInfo;
    this.radMaskedEditBox1.Culture = culture;
    calculatorElement.PopupClosed += calculatorElement_PopupClosed;
    calculatorElement.BorderPrimitive.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
    calculatorElement.EditorContentElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
    StackLayoutElement stackPanel = new StackLayoutElement();
    stackPanel.Orientation = Orientation.Horizontal;
    stackPanel.Margin = new Padding(1, 0, 1, 0);
    stackPanel.Children.Add(calculatorElement);
    RadTextBoxItem tbItem = this.radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem;
    this.radMaskedEditBox1.MaskedEditBoxElement.Children.Remove(tbItem);
 
    DockLayoutPanel dockPanel = new DockLayoutPanel();
    dockPanel.Children.Add(stackPanel);
    dockPanel.Children.Add(tbItem);
    DockLayoutPanel.SetDock(tbItem, Telerik.WinControls.Layouts.Dock.Left);
    DockLayoutPanel.SetDock(stackPanel, Telerik.WinControls.Layouts.Dock.Right);
    this.radMaskedEditBox1.MaskedEditBoxElement.Children.Add(dockPanel);
}
 
private void calculatorElement_PopupClosed(object sender, RadPopupClosedEventArgs args)
{
    this.radMaskedEditBox1.Value = calculatorElement.Value;
}


I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Agung
Top achievements
Rank 1
answered on 13 Sep 2018, 09:59 AM

Hi Dess,

thanks for your help,

i just have covered some code and create some custom component

class calculator : Telerik.WinControls.UI.RadCalculatorDropDown
{
    RadTextBoxItem tbitem = new RadTextBoxItem();
    RadMaskedEditBox editBox = new RadMaskedEditBox();
 
    public calculator()
    {
        editBox = new RadMaskedEditBox();
        editBox.MaskType = MaskType.Numeric;
        editBox.Mask = "N4";
        CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture.Clone() as CultureInfo;
        tbitem = editBox.MaskedEditBoxElement.TextBoxItem;
        RadTextBoxItem ti = this.CalculatorElement.EditorContentElement.TextBoxItem;
        this.CalculatorElement.EditorContentElement.Children.Remove(ti);
        this.CalculatorElement.EditorContentElement.Children.Add(tbitem);
        tbitem.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
        base.ValueChanged += this.value_valuechanged;
    }
      
    //public double Nilai { get; set; }
      
    public override string ToString()
    {
        return string.Format("{0:N4}", base.Value);
    }
 
    private void value_valuechanged(object sender, EventArgs e)
    {
        try
        {
            //Nilai = Math.Round(double.Parse(base.Value.ToString(), System.Globalization.NumberStyles.Any), 5);
            editBox.Value = this.Value;
        }
        catch (StackOverflowException so)
        {
            throw so;
        }
        catch (Exception ex)
        {
            throw ex;
        }        
    }
 
}

 

thanks for helping

Regards

Agung

Tags
CalculatorDropDown
Asked by
Agung
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Agung
Top achievements
Rank 1
Share this question
or