Hi Mark,
The only other change I think you need to make is to change the EditAs property to Double. The format doesn't use quotes; think of it as whatever would be on the other side of a String.Format {0:P} format string. And, the way it's currently set up, to get "25%" you'd have to enter "0.25", rather than "25".
Otherwise, try the code below. It's basic but it's a start.
using System;
using
System.Collections.Generic;
using
System.Text;
using
Infragistics.Win.UltraWinEditors;namespace BarraCoder
{
public class PercentageTextBox : UltraTextEditor
{
protected override void OnBeforeExitEditMode(Infragistics.Win.BeforeExitEditModeEventArgs args)
{
if (!string.IsNullOrEmpty(base.textValue))
{
double candidate;if (!double.TryParse(string.Format("{0}", base.Value), out candidate))
{
args.Cancel =
true;throw new ApplicationException("Not a valid number.");
}
base.Value = candidate / 100;
string newText = string.Format("{0:P}", candidate/100);base.SetText(newText);
}
base.OnBeforeExitEditMode(args);
}
protected override void OnValueChanged(EventArgs args)
{
System.Diagnostics.Debug.WriteLine(string.Format("New Value: {0}", base.Value));base.OnValueChanged(args);
}
}
}