Percent Formatting with a Data Bound TextBox

  • Thread starter Thread starter Cincy Steve
  • Start date Start date
C

Cincy Steve

Guest
I have been trying without luck to use a data bound TextBox into which the user will enter a percentage. There are 2 things that Id like that seem to be incompatible:

1. Id like the user to be able to enter just "3.5" (or perhaps even "3.5%") when they want 3.5%.

2. Id like the result displayed as 3.5%.

The problem is that entering 3.5 displays as 350% since the formatted data binding (see below) assumes the user input needs to be multiplied by 100.

Ive tried to muscle my way around it by not using the "P1" format in Binding and instead deriving my own TextBox and adding a "%" to the end of the Text in the Validated event handler. That works when the user enters data, but I cant get the "%" to appear when the control is initially drawn.

Is there any way to get what Id like?

Thx. Steve


myTextBox.DataBindings.Add(new Binding("Text", myBindingSource, "ColumnName", true, DataSourceUpdateMode.OnValidation, " ", "P1"));

Continue reading...
 
Back
Top