Results 1 to 4 of 4

Thread: [RESOLVED] [02/03] textbox date formatting

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Resolved [RESOLVED] [02/03] textbox date formatting

    hi all,

    i'm having problems formatting my textbox at form_load... and as much as possible i want to format it before or right after i bind it to my data table... which ever is possible.

    these are the codes i've used but didn't work... i have place it on the Form_Load Event

    Code:
    txtBirthdate.DataBindings.Add("Text", DT_CUST, "birthdate")
    txtBirthdate.Text = Format(txtBirthdate.Text, "dd-MMM-yy")
    then i tried this as well but no luck.

    Code:
    txtBirthdate.DataBindings.Add("Text", DT_CUST, "birthdate")
    txtBirthdate.Text = Format(CStr(txtBirthdate.Text), "dd-MMM-yy")
    then i tried placing these codes on a button and it worked but it would be inconvenient to push a button just to format a textbox to a date format.

    any suggestions? thanks.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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

    Re: [02/03] textbox date formatting

    Use a DateTimePicker, not a TextBox.
    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

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: [02/03] textbox date formatting

    ok thanks... this way is much better.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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

    Re: [RESOLVED] [02/03] textbox date formatting

    The only drawback is that the DTP doesn't support binding null values. If your column can contain nulls then you either have to forego data-binding or modify the DTP control. The library in my signature contains just such a modified DTP, but only the .NET 2.0 version is available from the link. If you e-mail them I'd guess that they'd supply the .NET 1.1 version for you.
    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

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