Solved

Change Format of DBGrid display

Posted on 2003-12-07
8
466 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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