Solved

Change Format of DBGrid display

Posted on 2003-12-07
8
474 Views
Last Modified: 2010-04-05
Hi..

I would like to change the display in the DBGrid.. In the database, I keep a field named DatePay with field type Date. I use DBase as my database type. So, the display of the date will be normally in 1/1/2003 format. Now I want to display this table in the DBGrid, but I want to change the display of DatePay field into: 1 Jan 2003. Is there anyway I can do this? Thankss :)
0
Comment
Question by:pipinana2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 5

Accepted Solution

by:
snehanshu earned 50 total points
ID: 9894661
pipinana2002,
  Here's a code that works for me: I set the displayformat property of the table'sdate field to whatever is required.
  Alternatively, I tried setting shortdateformst to  'd mmm yyyy' and that worked too.
  You could set
  ShortDateFormat := 'd mmm yyyy';
in the application's main form's oncreate event.
  Hope that helps,
...Snehanshu

Alternate code, to set the display format of the table's field:

procedure TForm1.Button1Click(Sender: TObject);
begin
   MyTable.Insert;
   ShortDateFormat := 'dd/mm/yyyy';

//DBGrid shows 1 jan 2003 irrespective of shortdateformat due to:
   (MyTable.FieldByName('MyDate') as TDateTimeField).DisplayFormat := 'd mmm yyyy';

   MyTable.Fields[0].AsDateTime := StrToDate('01/01/2003');
   MyTable.Fields[1].AsString := 'Snehanshu';
   MyTable.Post;
   ShortDateFormat := 'yyyy/mm/dd';
end;
0
 

Author Comment

by:pipinana2002
ID: 9894720
Hi snehanshu

Thanks a lottttt for your helppp :) It works well.. Hehehehe.. U're very very greatt! :D
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9894748
pipinana2002,
  Glad to know I could help. Thank you for the grade and the kind words :-)
...Shu
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9895575
just to say,
there is no need to change the shortdateformat
--> just change the displayformat of the underlying field

meikl ;-)
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10539448
I was looking at my bookmarks today and read this.
Meikl,
>>just change the displayformat of the underlying field
Can you show me how?

Thanks,
...Shu
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10539475
for example (you can also use the dataset directly)
anywhere at startup, maybe in the afteropen-event of the dataset

TDateTimeField(dbgrid1.Datasource.Dataset.FieldByName('YourFieldName')).DisplayFormat := 'dd.mm.yyyy';

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10539485
to go with the question

TDateTimeField(dbgrid1.Datasource.Dataset.FieldByName('YourFieldName')).DisplayFormat := 'd mmm yyyy';

meikl ;-)
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 10539508
Thanks Meikl!!

Pls post a comment here:
http://www.experts-exchange.com/Q_20910740.html

So that I can give you points.

...Shu
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question