Solved

Change Format of DBGrid display

Posted on 2003-12-07
8
447 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now