Results 1 to 16 of 16

Thread: txtbox format

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    txtbox format

    what the best way to format a textbox that is going to accept a price with a decimal: 11.99

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: txtbox format

    accept only five chars(two digits on the left , dot , two digits on the right)

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: Re: txtbox format

    This is what I mean . Actually you have different techniques but this is an example .

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Sorry forgot the important thing : attachment!
    Attached Files Attached Files

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Another method may be to use the public event Validating - inherited from Control. Unlike Pirate's example, where you capture keystrokes (which is very cool and gives you lots of control), this event fires after you leave the control.

    There's a good example in the help where this event is explained.

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    The demo I've uploaded can capture keys too that you don't need . That would prevent the user from typing more than 5 chars in textchanged event (which is more efficient way than validating after the user finishes typing ) .Can you tell more about things about that Mike Hildner .

  7. #7
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Personally, I like capturing the key presses, because it gives you a lot of control. Whether it's more effecient or not, I don't know. I just wanted to mention another method. Always nice to have options.

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , I know it's good , but this can exactly does the job as Validation (although the latter has some problems , and sometimes guys suffer from it ).

  9. #9
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    If you want i can provide the backend code for a custom txtbox control that i wrote. This control provides you with the following validation options

    decimal
    currency (includes $ and pound signs)
    numeral only
    email
    url
    text only
    anything goes

    let me know if you would like to see how i achieved this

  10. #10
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Not sure who you're asking, but I'd like you to post. I'm new to .NET and would like an example to study.

    TIA,
    Mike

  11. #11
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    okay well here is the code
    Attached Files Attached Files

  12. #12

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    pirate is there a way to only allow the user two spaces after they put in a decimal?

  13. #13

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    also, I have two textboxes that are going to accept prices. One is going to accept the Total and the other Sales Tax. I need to add these to values and store it into a variable. What do I declare the variable as? A double or a decimal?

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by EyeTalion
    pirate is there a way to only allow the user two spaces after they put in a decimal?
    The easiest way is : set Max Length of a textbox to 7 chars .

  15. #15

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    cool...thanks for all the help guys

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    forgot about this one

    The most suitable variable type for this case would be Decimal which can handle more digits on both sides of the decimal point .
    Why don't you use any array instead of variables ?

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