Results 1 to 3 of 3

Thread: [RESOLVED] [2.0] Max Length, eh?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Resolved [RESOLVED] [2.0] Max Length, eh?

    Someone help me out here? I can set the max length of a textbox to 8 but when I do something it can still input a number greater than 8 into the textbox. For example, if I push a button it can put 8+ letters or numbers in it. The reason I want this is because I have this code for a DateTimePicker ValueChanged event:

    firsthoursbox.Text = Convert.ToString(firstendbox.Value - firststartbox.Value);

    And.. When I first click it. It will give something like 00:59:59.8750000

    It's kind of annoying.. Someone help me out here? Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Max Length, eh?

    As always, the first thing to do is to read the relevant dicumentation. Here's a quote from the help topic for TextBox.MaxLength:
    In code, you can set the value of the Text property to a value that has a length greater than the value specified by the MaxLength property. This property only affects text entered into the control at run time.
    I imagine that the rationale is that it's your code and if you don't want to put a string longer than eight characters in the text box then you won't. If you don't want that entire string in the text box then either use String.Format to create exactly the string you want or else use String.Substring to remove the characters you don't want.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Hyperactive Member BrandonTurner's Avatar
    Join Date
    Sep 2001
    Location
    East Lansing, Michiagn
    Posts
    268

    Re: [RESOLVED] [2.0] Max Length, eh?

    Might want to look into a masked textbox with a mask of "########" or something along those lines.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width