RadNumericUpDown control with custom unit as ft in (feet inch e.g., 99 ft 1 in)

1 Answer 37 Views
GridView NumericUpDown
Hirenkumar
Top achievements
Rank 1
Hirenkumar asked on 31 Oct 2023, 11:06 AM

Dear Telerik Team,

I am using the RadNumericUpDown control for accepting the numeric value. I have made hidden the up and down tick button so it look like simple textbox. The purpose of using this control specific for Distance and Weight values so it can be in any unit of measurement. For example, meter, millimeter, feet, kg, ton etc.

For simple UOM like meter, I can simply set the CustomUnit as "m" and it works fine. But How can I represent the value of 99.11 feet to feet and inch e.g., 99 ft 1 in

So whenever user trying to edit the value, it will be in feet only and once it is edited value will be displayed in feet and inch. 

How can  I achieve this behavior using RadNumericUpDown control ?

Thanks & Regards,

Hiren Lad

1 Answer, 1 is accepted

Sort by
1
Accepted
Dinko
Telerik team
answered on 01 Nov 2023, 10:37 AM

Hello Hirenkumar,

You can achieve the desired requirement by deriving from the RadNumericUpDown class and overriding the FormatDisplay and FormatEdit methods:

public class MyCustomNumericUpDown : RadNumericUpDown
{
	public override string FormatDisplay()
	{
		if (this.Value.HasValue)
		{
			return Value.Value.ToString();
		}

		return base.FormatDisplay();
	}
	
	public override string FormatEdit()
	{
		if (this.Value != null)
		{
			// Get the value in feet
			double? feetValue = this.Value;

			// Convert to feet and inches
			int feet = (int)feetValue;
			double? remainingInches = (feetValue - feet) * 12;
			int inches = (int)remainingInches;

			return $"{feet} ft {inches} in";
		}

		return base.FormatEdit();
	}
}

You can see the result in the following image:

For your convenience I prepared a sample solution and a short video where this behavior is implemented.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Hirenkumar
Top achievements
Rank 1
commented on 06 Nov 2023, 11:42 AM

Thanks Dinko, Its working for me.
Tags
GridView NumericUpDown
Asked by
Hirenkumar
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Share this question
or