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 | Calendar | 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 18th, 2004, 03:29 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default bindings & date format

Hi to all!

I am getting an error when I try to do the next format adjustment:

Binding b50;
b50 = new Binding("Text", dsPacientes, "PACIENTES.pac_fecha_nac");
b50.Format += new ConvertEventHandler(this.txtFechaFormat);
txtFechaNac.DataBindings.Add(b50);

...

private void txtFechaFormat(object sender, ConvertEventArgs e)
{
   DateTime dt = (DateTime) e.Value;
   e.Value = dt.ToString("MM/dd/yyyy hh:mm:sszzz");
}

The problem is inside the function "txtFechaFormat". I've tried out with diff formats, with no results.

Does anybody can help me?

Thanks
Reply With Quote
  #2 (permalink)  
Old August 18th, 2004, 08:53 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

WE can best help people when they provide the error they are getting.

That said, i might be missing something- but this code doesn't even look like it's close to being correct.


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply With Quote
  #3 (permalink)  
Old August 18th, 2004, 01:10 PM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok. The error is:

'System.InvalidCastException' in system.windows.forms.dll

Additional information: The specified conversion is not valid.

I hope it helps.
Reply With Quote
  #4 (permalink)  
Old August 18th, 2004, 02:22 PM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

and e.value takes a string?


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
Reply With Quote
  #5 (permalink)  
Old August 18th, 2004, 02:44 PM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think so.

I used it like i read in "binding in windows forms applications" from the help

-------------------------------
World only exists into your mind.
Reply With Quote
  #6 (permalink)  
Old August 18th, 2004, 03:38 PM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Hal,

I've finally solved, in the way:

private void txtFechaFormat(object sender, ConvertEventArgs e)
{
   DateTime dt = (DateTime) e.Value;
   string s = dt.ToString("dd/MM/yyyy");
   e.Value = s;
}

I really don't understand at all, because I am doing the same... or that's what I think... never mind, it works fine.

:)

-------------------------------
World only exists into your mind.
Reply With Quote
  #7 (permalink)  
Old August 22nd, 2004, 10:47 PM
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

excuse me what about giving format in a grid?! how can I format a cell in a grid?!

Always:),
Hovik Melkomian.
Reply With Quote
  #8 (permalink)  
Old August 25th, 2004, 02:49 AM
Authorized User
 
Join Date: Nov 2003
Location: Mataro, Barcelona, Spain.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I don't use datagrids. I don't know.

-------------------------------
World only exists into your mind.
Reply With Quote
  #9 (permalink)  
Old August 25th, 2004, 06:10 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

yes,Hovik we can do it easily...
Code:
<asp:BoundColumn DataFormatString="{0:d}" DataField="yourColumn"></asp:BoundColumn>
--------------------------------------------
Mehdi.:)
Reply With Quote
  #10 (permalink)  
Old August 25th, 2004, 03:33 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Also in response to Hovik, the date format in your datagrid is based on the date format of the users regional settings. I couldn't figure out a way to change the date format in my datagrid for my non ASP application without changing it in the Regional Settings. If somebody knows of a way and would like to share, please feel free...

Devon

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
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM
Date/Time format & multiple selection with listbox frmsasp ASP.NET 1.0 and 1.1 Basics 0 October 13th, 2005 05:50 AM
* where date >= '"& dateVar &"' order by date wrofox Classic ASP Databases 5 February 24th, 2005 10:11 AM
bindings & images miguel.ossa C# 1 August 20th, 2004 01:02 AM



All times are GMT -4. The time now is 10:45 PM.


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