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

Extend RadspinEditor control to accept + sign for positive numbers

1 Answer 123 Views
SpinEditor
This is a migrated thread and some comments may be shown as answers.
aravind rajagopal
Top achievements
Rank 1
aravind rajagopal asked on 21 Feb 2013, 05:26 AM
Hi,

I was creating an application for Opticals. They want increase/decrease the power details using radspin editor.
And they want to see the + sign for positive numbers like +1.25  (like Negative sign is showing for negative  numbers).

How can I extend the radspinEditor to achive this result.

thanks
Aravind Rajgopal

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 25 Feb 2013, 03:35 PM
Hi Aravind,

Thank you for writing.

The RadSpinEditor does not support formatting in this way. 
However, you can try to work-around with adding a '+' sign in the TextChanged event. For example:
radSpinEditor1.SpinElement.TextBoxItem.TextChanged += new EventHandler(TextBoxControl_TextChanged);
 
 
bool internalChange;
void TextBoxControl_TextChanged(object sender, EventArgs e)
{
    if (internalChange) return;
    internalChange = true;
 
    RadTextBoxItem textBox = (RadTextBoxItem)sender;
    if (!textBox.Text.Contains("-"))
    {
        int selection = textBox.SelectionStart;
        textBox.Text = textBox.Text.Replace("+", "");
        textBox.Text = "+" + textBox.Text;
        if (selection == 0)
        {
            selection = 1;
        }
 
        textBox.SelectionStart = selection;
    }
    else
    {
        textBox.Text = textBox.Text.Replace("+", "");
        textBox.SelectionStart++;
    }
 
 
    internalChange = false;
}

Please, keep in mind that I cannot guarantee that everything will work as expected in all possible cases when using this work around.

I hope this helps.

Kind regards,
Peter
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
SpinEditor
Asked by
aravind rajagopal
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or