zattz
asked on
Change Date format in DBGrid
Hi
I have a DBGRID hooked up to a datasource with .NET datetime fields.
The dates are displaying as "MM/DD/YYYY 00:00:00"
How can I get rid of the time part in the grid display?
Thanks
I have a DBGRID hooked up to a datasource with .NET datetime fields.
The dates are displaying as "MM/DD/YYYY 00:00:00"
How can I get rid of the time part in the grid display?
Thanks
that's a good way. another way is to add your fields as persistent fields in the dataset (as Geert instructs) and then use the onsettext for the relevant field.
ASKER
I am using the dbgrid in vcl.net and there is no displayformat for the columns
not on the dbgrid no, it's on the dataset component ...
and only for TDateTime Fields !
like
TDateTimeField(TQuery.Fiel dByName('F IELDNAME') ).DisplayF ormat
the ordinary TField doesn't have the property, it must be cast to TDateTimeField
and only for TDateTime Fields !
like
TDateTimeField(TQuery.Fiel
the ordinary TField doesn't have the property, it must be cast to TDateTimeField
Another approach is this :
Usually people enter data into the grid (insert) by the use of the DateTimePicker.
So do it over there..Set format over there..
cxDateEdit has SaveTime and ShowTime options
Usually people enter data into the grid (insert) by the use of the DateTimePicker.
So do it over there..Set format over there..
cxDateEdit has SaveTime and ShowTime options
this is for a DBGrid not a DevExpress Grid ...
ASKER
I am using delphi.net so the type is DateTime and not TDateTime.
Still have not resolved the issue
Still have not resolved the issue
zattz> Go to your dataset, double-click it, a new window pops up. Right click in the window and select Add All Fields. You've just made the fields of your dataset "persistent". Click on the relevant field (e.g. "MyDateField") and in the object inspector look under displayFormat.
sigh...
sigh...
how long have you been using Delphi (.Net has nothing to do with this ...)
or read this first:
http://veerle-en-geert.be/delphi/ebooks/Delphi%20-%20Teach%20Yourself%20Borland%20Delphi%204%20in%2021%20Days.pdf
specially as from chapter 16
or read this first:
http://veerle-en-geert.be/delphi/ebooks/Delphi%20-%20Teach%20Yourself%20Borland%20Delphi%204%20in%2021%20Days.pdf
specially as from chapter 16
ASKER
rfwoolf, it is a third party dataset that does not work the way the old VCL ones did, which is why I wanted to do it when the grid draws.
zattz> Well I think you can technically use the grid drawing - worth a shot.
Here's a link to an about.com tutorial on using color in the DBgrid. What we're going to be doing instead is using this same technology but changing the values of the cells...
http://delphi.about.com/od /usedbvcl/ l/aa031699 .htm
I don't have delphi open so you may have to figure this out yourself, but basically, in your OnDrawColumnCell even of the DBGrid, having anything in there will overwrite the default drawing procedure of the DBGrid. Once you've done that just make sure you call DefaultDrawColumnCell in such a way that instead of putting the normal text of the field, it will put a formatted text of the field.
Here's an example to get you started.
Later when I'm feeling better I might open delphi and try figure this out for you.
Here's a link to an about.com tutorial on using color in the DBgrid. What we're going to be doing instead is using this same technology but changing the values of the cells...
http://delphi.about.com/od
I don't have delphi open so you may have to figure this out yourself, but basically, in your OnDrawColumnCell even of the DBGrid, having anything in there will overwrite the default drawing procedure of the DBGrid. Once you've done that just make sure you call DefaultDrawColumnCell in such a way that instead of putting the normal text of the field, it will put a formatted text of the field.
Here's an example to get you started.
Later when I'm feeling better I might open delphi and try figure this out for you.
procedure TForm1.DBGrid1DrawColumnCell
(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
DBGrid1.DefaultDrawColumnCell
(Rect, DataCol, Column, State);
end;
which 3rd party dataset is it ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you have to add the fields to the dataset, by right clicking on the component in the form editor
and select add all fields
or
procedure TForm1.FormCreate(Sender: TObject);
begin
TDateTimeField(Query1.Fiel
end;