p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# (http://p2p.wrox.com/forumdisplay.php?f=22)
-   -   bindings & date format (http://p2p.wrox.com/showthread.php?t=17028)

miguel.ossa August 18th, 2004 03:29 AM

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

Hal Levy August 18th, 2004 08:53 AM

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

miguel.ossa August 18th, 2004 01:10 PM

Ok. The error is:

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

Additional information: The specified conversion is not valid.

I hope it helps.

Hal Levy August 18th, 2004 02:22 PM

and e.value takes a string?


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee

miguel.ossa August 18th, 2004 02:44 PM

I think so.

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

-------------------------------
World only exists into your mind.

miguel.ossa August 18th, 2004 03:38 PM

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.

melvik August 22nd, 2004 10:47 PM

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

Always:),
Hovik Melkomian.

miguel.ossa August 25th, 2004 02:49 AM

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

-------------------------------
World only exists into your mind.

mehdi62b August 25th, 2004 06:10 AM

yes,Hovik we can do it easily...
Code:

<asp:BoundColumn DataFormatString="{0:d}" DataField="yourColumn"></asp:BoundColumn>
--------------------------------------------
Mehdi.:)

dcathers August 25th, 2004 03:33 PM

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



All times are GMT -4. The time now is 06:25 AM.

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