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

New control RadButtonTextBox with Decimal textbox

1 Answer 236 Views
TextBox
This is a migrated thread and some comments may be shown as answers.
Moi
Top achievements
Rank 1
Moi asked on 15 May 2019, 06:39 PM

Hi,

I contact you about the new RadButtonTextBox control in winforms.

This control is perfect however can you tell me if is it possible to configure the textbox for decimal format ?

I would like to use this control in a Editor griview cell with element inherits of RadButtonTextBoxElement and replace this textbox by a decimal textbox ?

Thank you

Bests regards

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2019, 11:04 AM
Hello, Moi,     

Instead of using a RadButtonTextBoxElement, I would recommend you to use a RadMaskedEditBoxElement with numeric mask. Thus, you can ensure that only numeric values will be entered. In addition, it is possible to add as many buttons as you which in the hosted TextBox.

I have prepared a sample code snippet for your reference demonstrating how to achieve a numeric button text box as an editor in RadGridView:

Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.

private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (this.radGridView1.CurrentColumn.Name == "UnitPrice")
    {
        e.EditorType = typeof(MyEditor);
    }
}
 
public class MyEditor : BaseGridEditor
{
    public override object Value
    {
        get
        {
            RadMaskedEditBoxElement editor = (RadMaskedEditBoxElement)this.EditorElement;
            return editor.Value;
        }
        set
        {
            RadMaskedEditBoxElement editor = (RadMaskedEditBoxElement)this.EditorElement;
            if (value != null && value != DBNull.Value)
            {
                editor.Value = Convert.ToDecimal(value);
            }
            else
            {
                editor.Value = 0;
            }
        }
    }
 
    public override void BeginEdit()
    {
        base.BeginEdit();
        RadMaskedEditBoxElement editor = (RadMaskedEditBoxElement)this.EditorElement;
 
        this.EditorElement.Focus();
    }
 
    void TrackBarEditor_TrackPositionChanged(object sender, EventArgs e)
    {
        OnValueChanged();
    }
 
    protected override RadElement CreateEditorElement()
    {
        RadMaskedEditBoxElement el = new RadMaskedEditBoxElement();
         
        //specify numeric mask
        el.MaskType = MaskType.Numeric;
        el.Mask = "N2";
         
        //add button elements
        RadButtonElement button = new RadButtonElement();
        button.Click += new EventHandler(button_Click);
        button.Padding = new Padding(2, 0, 2, -2);
        button.Margin = new Padding(0, 0, 0, 0);
        button.Text = "...";
        RadButtonElement button2 = new RadButtonElement();
        button2.Click += new EventHandler(button_Click);
        button2.Padding = new Padding(2, 0, 2, -2);
        button2.Margin = new Padding(1, 0, 2, 0);
        button2.Text = "///";
        RadButtonElement button3 = new RadButtonElement();
        button3.Click += new EventHandler(button_Click);
        button3.Padding = new Padding(2, 0, 2, -2);
        button3.Margin = new Padding(1, 0, 1, 0);
        button3.Text = @"\\\";
        StackLayoutElement stackPanel = new StackLayoutElement();
        stackPanel.Orientation = Orientation.Horizontal;
        stackPanel.Margin = new Padding(1, 0, 1, 0);
        stackPanel.Children.Add(button);
        stackPanel.Children.Add(button2);
        stackPanel.Children.Add(button3);
 
        RadTextBoxItem tbItem = el.TextBoxItem;
        el.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);
        el.Children.Add(dockPanel);
 
        return el;
    }
 
    private void button_Click(object sender, EventArgs e)
    {
        //TODO
    }
}



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

Regards,
Dess | Tech Support Engineer, Sr.
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.
Tags
TextBox
Asked by
Moi
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or