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.
Unfortunately, activation email could not send to your email. Please try again.

PercentTextBox binding

Thread ID:

Created:

Updated:

Platform:

Replies:

95482 Jul 12,2010 07:09 PM Jul 16,2010 05:03 AM Windows Forms 5
loading
Tags: Tools
Administrator [Syncfusion]
Asked On July 12, 2010 07:09 PM

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?

Administrator [Syncfusion]
Replied On July 12, 2010 07:34 PM

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.

Vallarasu S [Syncfusion]
Replied On July 15, 2010 05:41 AM

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.

Administrator [Syncfusion]
Replied On July 15, 2010 11:57 AM

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.

Administrator [Syncfusion]
Replied On July 15, 2010 01:44 PM

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;
}


Vallarasu S [Syncfusion]
Replied On July 16, 2010 05:03 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;