Solved

Change Format of DBGrid display

Posted on 2003-12-07
8
455 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 80
Delphi Mdi application Child forms get behind control 7 153
Can Viruses spread while transferring Binary data with Winsock 2 66
DBGrid or StringGrid ? 6 65
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now