We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PercentTextBox binding

I'm having some trouble binding a field in a data source to the PercentTextBox.

I'm using the BindablePercentValue property and it seems to "get" the value from the input and store it in the data source correctly but the control always displays "0.00%"
If I use PercentValue property instead, then actual binding doesn't seem to work - the value never gets set in the data source properly (although, it doesn't revert to "0.00%").

Any ideas?

5 Replies

AD Administrator Syncfusion Team July 12, 2010 11:34 PM UTC

Further on this...
I started binding to the DoubleValue property and that seems to work much better.
It also allows us to format the values in a way we've always desired which is to format a value like .45 as "45 %" rather than "0.45 %".

but...it doesn't seem to deal with null values very well.


VS Vallarasu S Syncfusion Team July 15, 2010 09:41 AM UTC

Hi Mark,

Thanks for using Syncfusion products,

It seems the controls BindableValue property works as expected, the behavior of the control is that when null value is set
the control will display the value '0.00%' ( default value of the NullString property).
if you want to show an empty string in the text field when it is set with null you can do so with the NullString Property
as follows.

this.percentTextBox1.UseNullString = true;
this.percentTextBox1.NullString = string.Empty;

Regarding the DoubleValue property, a double can not be null.

Please let us know if you have concerns on this.

Regards
Vallarasu S.


AD Administrator Syncfusion Team July 15, 2010 03:57 PM UTC

When I use the BindableValue property, it seems to work like the BindablePercentValue property - I can enter in the number but the control reverts back to "0.00 %" even though the data has been set.


AD Administrator Syncfusion Team July 15, 2010 05:44 PM UTC

I think the problem I'm seeing is due to the way PercentTextBox.SetValue is implemented.

The object coming into that method is cast as a string (val as string) so it can be parsed using double.TryParse.
But, in my case, the object isn't a string, it's a double. So the cast turns it into NULL and the resulting value is 0.
It's as if the PercentTextBox is assuming that the data type of the thing it is binding to is a string.

I've overridden the SetValue method to look like this and that works for me:

protected override void SetValue(object val)
{
double num = 0;
if (val != null)
{
if (!double.TryParse(val.ToString(), NumberStyles.Number, NumberFormatInfoObject, out num))
num = 0;
}

DoubleValue = num;
}



VS Vallarasu S Syncfusion Team July 16, 2010 09:03 AM UTC

Hi Mark,

Thanks for the update,

We are glad to hear that you have a solution to your problem,

Please let us know if you need further assistance.

Regards
Vallarasu S.

Loader.
Live Chat Icon For mobile
Up arrow icon