Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OnLostFocus issue with UniversalTextBox

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
keesp
Guest





PostPosted: Thu Oct 06, 2005 1:52 pm    Post subject: OnLostFocus issue with UniversalTextBox Reply with quote

Hi,

I am trying to get to situation where the edited value in a UniversalTextBox is updated the moment I click on a position outside the textbox area. I would have thought that this moment is captured by an OnLostFocus event, but this does not seem to be the case. What is the best way to achieve this behaviour?

Regards,

Kees
Back to top
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Oct 06, 2005 10:47 pm    Post subject: Reply with quote

Normally this is done by overriding the OnValidating method. For UniversalEditBox the default implementation of OnValidating is:

Code:

        protected override void OnValidating(CancelEventArgs e)
        {
            if (TextEditable)
            {
                e.Cancel = !ValidateText();
            }
            base.OnValidating (e);
        }


The ValidateText method in turn is implemented as:

Code:

        /// <summary>
        /// Validate the user entered text and set the Value property
        /// </summary>
        /// <returns>True if the text was valid and Value was set</returns>
        protected virtual bool ValidateText()
        {
            try
            {
                Value = Converter.ConvertFromString(this, CultureInfo.CurrentCulture, TextBox.Text);
            }
            catch (Exception e)
            {
                return HandleTextConversionError(e);
            }
            return true;
        }


So this converts the text to the ValueType - setting Value will then cause the displayed Text to be updated (using the TypeConverter)


If what you are trying to achieve is the original post:

Quote:
I want to format the strings that are displayed in the universal editbox (the provided data may be any object), so that, for instance, when the ToString() of an object I provide returns the string representation of a double like 0.12345678, I can just show 0.123.
What is the best way to tackle this?


Then I think it would be much simpler to create a "DoubleTypeConverter" that when converting the double to string formats it with your desired accuracy.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
keesp
Guest





PostPosted: Fri Oct 07, 2005 10:24 am    Post subject: onlostfocus Reply with quote

Hi,

The formatting has been sufficiently resolved using the advice of another post, using the GetTextForValue method, see "using format in Universal edit box".
I am just concentrating on the this bit of behaviour now.., I'll try it!
Thanks

Kees
Back to top
keesp
Guest





PostPosted: Tue Oct 11, 2005 10:20 am    Post subject: using lost focus of text box Reply with quote

I am getting the required behaviour by subscribing my derived textbox to the lostfocus event of the internal textbox (in the constructor):

this.TextBox.LostFocus +=new EventHandler(TextBox_LostFocus);

and applying the type converter in the event handler:

/// <summary>
/// Respond to the lost focus event of the internal text box in order to
/// immediately update edited values
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TextBox_LostFocus(object sender, EventArgs e)
{
Value = Converter.ConvertFromString(this, CultureInfo.CurrentCulture, TextBox.Text);
}

This works fine!

Thanks again

Kees
Back to top
keesp
Guest





PostPosted: Thu Oct 13, 2005 8:25 am    Post subject: a small addition Reply with quote

In order to handle incorrect entries, it is advisable to put a try / catch around the

Value = Converter.ConvertFromString(this, CultureInfo.CurrentCulture, TextBox.Text);

In the catch thread, one could for instance set the fore color of the internal textbox red or something.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group