Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 28th, 2003, 02:52 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default formatting TextBox

How can I format TextBox to a date format like: YYYY/MM/DD
I'll be thankful.

Always:),
Hovik Melkomian.
__________________
Always,
Hovik Melkomian.
Reply With Quote
  #2 (permalink)  
Old August 28th, 2003, 07:26 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you just want to use the date format of the current locale then you can use something like this:

DateTime dt = Convert.ToDateTime(this.txtDate.Text);
this.txtDate.Text = dt.ToShortDateString();

However, if you want to force YYYY/MM/DD then there are a couple of options. The simplest is probably this, but it's fairly messy:

DateTime dt = Convert.ToDateTime(this.txtDate.Text);
this.txtDate.Text = dt.Year.ToString() + "/" + dt.Month.ToString() + "/" + dt.Day.ToString();

Alternatively, the "proper" way to do this (which is a fair bit more elegant) is:

DateTime dt = Convert.ToDateTime(this.txtDate.Text);
this.textBoxDate.Text = String.Format("{0:yyyy/MM/dd}", dt);

Reply With Quote
  #3 (permalink)  
Old August 28th, 2003, 07:33 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

tnx 4 reply & ur time!

Always:),
Hovik Melkomian.
Reply With Quote
  #4 (permalink)  
Old August 28th, 2003, 07:39 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

hi again, sorry:
How can I make the TextBox Selected.
In textBox of WebContols when the textBox is not empty in focus mode its selected my defualt?! Sould I code for that in Focus or there is a prperty?! I couldnt find it?!

I'll be thankful.


Always:),
Hovik Melkomian.
Reply With Quote
  #5 (permalink)  
Old August 28th, 2003, 07:45 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If it's on a web page then you generally need to use JavaScript to set the focus on whatever control you want, like for example:

<SCRIPT language="JavaScript">
   //Works in IE and netscape
   document.getElementById("theASPdotNETID").focus();

   //Works in IE only
   document.all.theASPdotNETID.focus();
</SCRIPT>

Reply With Quote
  #6 (permalink)  
Old August 28th, 2003, 08:00 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

I asked about WindowsApp. I know how its in Web. How shoudl I do it in Windows App.?!?!?

Always:),
Hovik Melkomian.
Reply With Quote
  #7 (permalink)  
Old August 28th, 2003, 08:14 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry about that...
To set the focus in a Windows App use

FormName.ActiveControl = this.textBox;

or whatever. For some reason the textBox.Focus() method doesn't always seem to work in the load event of a form.

Reply With Quote
  #8 (permalink)  
Old September 11th, 2003, 03:04 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

If I have my date in YYYYMMDD format how can I format it to YYYY/MM/DD.
Any help is appreciated.

Always:),
Hovik Melkomian.
Reply With Quote
  #9 (permalink)  
Old September 11th, 2003, 06:45 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To do that you shouldn't need to use any DateTime objects. Just use string manipulation:

string dbDate = "20030911";
dbDate = dbDate.Substring(0, 4) + "/" + dbDate.Substring(4, 2) + "/" + dbDate.Substring(6, 2);

I can't find any other way of doing it, if anyone else can I'd be interested to hear it. If you need it as a DateTime object in the end you can just use, e.g.

DateTime dt = Convert.ToDateTime(dbDate);

Reply With Quote
  #10 (permalink)  
Old September 11th, 2003, 06:58 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear Edvard:
tnx for ur fast reply but I tryed it before & have some problem.
My data comes from DataBase using DataSet its in string format.
I DataBinded my field to TextBox & using dbDate = dbDate.Substring(0, 4) + "/" + dbDate.Substring(4, 2) + "/" + dbDate.Substring(6, 2); makes my program a little slower! Im guess I can do it with set & get the textBox but how dont know?!

Always:),
Hovik Melkomian.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox Number Formatting pencilneck Visual Basic 2005 Basics 2 October 25th, 2007 03:46 PM
pointing cursor from one textbox to other textbox lakshmi_annayappa ASP.NET 1.0 and 1.1 Basics 2 August 2nd, 2007 03:41 PM
Formatting TextBox bound to a database column Raby Visual Basic 2005 Basics 1 September 6th, 2006 07:47 PM
Textbox Formatting echovue Access 5 May 26th, 2006 09:47 AM
Masked TextBox & formatting TextBox melvik C# 1 September 22nd, 2003 11:01 AM



All times are GMT -4. The time now is 09:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.