locked
Formatting textboxes RRS feed

  • Question

  • How can I format a textbox to SHOW a number like 1.234.567,89 (if the number is big enough !) else just 1,23 og 0,00 if the number is zero.

    The textbox is Drag&Dropped from a datasource to the form and then I think bound to the field in the SQL-DB !



     
    Friday, December 12, 2008 1:26 PM

Answers

All replies

  • String.Format("{0:n}", textbox.text). make sure to validate your textbox input is a number


    carol
    Friday, December 12, 2008 2:28 PM
  • You could always handle the format event for the textbox's binding.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.binding.format.aspx

    Orlando Code Camp March 22, 2008 Call for Speakers is now open. http://www.orlandocodecamp.com
    • Marked as answer by PSAKSor Monday, December 15, 2008 9:36 AM
    Friday, December 12, 2008 3:34 PM
  • Hi PSAKSor,

    Based on my standing, you'd like to read a number from DB. And then display it in the textbox.
    If I am right, I advise you to take steps as below:
    First, get it out from your DB into a string.
    Then transfer it into the format you want to display.
    At last display it in the textBox.
    Wish this could help you.

    If I misunderstood you, please feel free to let me know.

    Best regards,
    Steven Yu
    Monday, December 15, 2008 9:07 AM
  • I think Ken Tucker had the solution
    Monday, December 15, 2008 9:37 AM
  • To all of you:

    There is NO need to do any code here !!!!

    You can do the job in the advanced databinding properties of each field !!!!

    I like to do it simple and easy - Occams razor !

    ;-))
    • Proposed as answer by JamesBuss Tuesday, September 4, 2012 1:29 PM
    Tuesday, December 16, 2008 10:45 AM