Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Percent Formatting with a Data Bound TextBox

$
0
0

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 I'd like that seem to be incompatible:

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

2. I'd 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. 

I've 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 can't get the "%" to appear when the control is initially drawn. 

Is there any way to get what I'd like?

Thx.  Steve

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




Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>