ejla51
asked on
Change Time format on DBGrid
I have a database table (TkbmMemTable) and stored time in the table is format "hh:mm:ss" but I want to format this to "hhmm" or "hh:mm" on DBGrids Time column...
How to do?
How to do?
ASKER
Ok... sorry, but my Time field is of String type :-(
Is there some way to set format?
Is there some way to set format?
Then you must reformat it by "hand". Set new event OnText to field:
... //somwhere on form create event
dbTable.FieldByName('field1').onText := tblTable1GetText;
...
procedure TForm.tblTable1GetText(Sender: TField; var Text: string;
DisplayText: Boolean);
begin
if Sender.FieldName='field1' then
begin
Text:=Copy(Sender.AsString, 1, 5); //or you can parse to values form EncodeTime
end;
end;
ASKER
>dbTable.FieldByName('fiel d1').onTex t := tblTable1GetText.
Thanks, but I can't found where put this line.
Have tried to put in Form.OnCreate and many other places too :-)
Compiler says "Undeclared identifier onText"
My table is located in Datamodule.
Thanks, but I can't found where put this line.
Have tried to put in Form.OnCreate and many other places too :-)
Compiler says "Undeclared identifier onText"
My table is located in Datamodule.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, but "Undeclared identifier onText" still appers!
ASKER
>dbTable.FieldByName('fiel d1').onTex t := tblTable1GetText
Is this really correct syntax -
and not dbTable.FieldByName('field 1').onGetText := tblTable1GetText instead?
Is this really correct syntax -
and not dbTable.FieldByName('field
Sorry, can be, depends on what db component you use, ado , bde, db express,... in design time look for OnText or OnGetText event in query and do double click to get procedure definition and put code there.
ASKER
I got it work at last...
- Moved OnGetText redirection after loading of binary file in MemTable. Has been in the DatamoduleCreate before.
- Memtable.Refresh; (was not there before)
- DBGrid.Refresh (needed too - otherwise mouseclick on Grid refresh display format)
Thanks!
//EL
- Moved OnGetText redirection after loading of binary file in MemTable. Has been in the DatamoduleCreate before.
- Memtable.Refresh; (was not there before)
- DBGrid.Refresh (needed too - otherwise mouseclick on Grid refresh display format)
Thanks!
//EL
Open in new window