Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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,101
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
  #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.
  #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,101
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
  #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.
  #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.
  #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.
  #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.
  #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.:)
  #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





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





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