• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Replacing Julian date in TDBGrid cells

Using Delphi 3, and a TDBGrid, one of the columns/fields displays a date in Julian format (e.g. "145667").

Since my brain cannot convert the Julian value in the DBGrid easily, I am wanting to have some way to display the Julian date as a more user friendly date.

I do NOT want to change the actual value in the linked database table. Instead, I just want the cells in the "Date" column/field to DISPLAY something besides what is in the actual database table.

What is the best way to approach this?  I could have all the Julian dates displayed as "MM-DD-YYYY" in the cells in the "Date" column,  or I could have a popup hint window appear with the converted date when the cursor hovers over a particular date cell.

Any other ideas?

In either case, I don't know how to do either of the above, so any code would likewise be appreciated.
0
Monroe406
Asked:
Monroe406
  • 3
  • 3
  • 2
1 Solution
 
viktornetCommented:
Hello Monroe!

Would you please tell me what the converted date of 145667 would be??

-Viktor
--Ivanov
0
 
Monroe406Author Commented:
>> Would you please tell me what the converted date of 145667 would be??

Using my head...it would be approx. November 20, 1998.

I don't want you to get hung up on the date conversion part, however.   I will handle the conversion from Julian back to MM-DD-YY.  All I want is to know how to get change the text that is displayed in the TDBGrid's DATE column.
0
 
viktornetCommented:
Try using OnColEnter() and OnColExit()

after that try using dbgrid.MouseCoord() and similar that take the X and Y values to see where you are in the grid, and then display a hint depending on where you are in the Db grid...

Then use       DBGrid1.hint to set the hint and display it... ok i think that will help you do what you want...

-Viktor
--Ivanov
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Monroe406Author Commented:
Thanks, but there is too much missing from your suggestion...such as...

+ How to determine WHICH column the user has clicked in.

+ How to determine the contents of the cell (row/column) which the user has clicked in

+ How to place the Hint window over top of the cell that has been clicked in.

These would be necessary for your suggestion to be acceptable.

0
 
viktornetCommented:
I tried this one with TStringGrid and it worked... I don't know if it works with the DBGrid...

StringGrid.ShowHint := true; //The ShowHint of the string grid is set to true...

sg = StringGrid

OnMouseMove()
var
  Col, Row : Integer;
begin
  sg.MouseToCell(x, y, Col, Row);
   if (Col > 0) and (Col < sg.ColCount-1) and (Row > 0) and (Row < sg.RowCount-1) then
     sg.Hint := sg.Cells[Col, Row];
end;

Then everything works okay and the contents in the cell is shown as it's suppose to be... try it out with the DB Grid and tell me how it works.. If it doesn't work then reject my answer 'cuz i don't really have much time to work on this.. 10q

Happy New Year!

-Viktor
--Ivanov
0
 
dwwangCommented:
Hi, Monroe406

Firstly, 145667 is Oct. 26, 1998

Secondly, what you need is to use the OnGetText of the query/table component with you dbgrid connected to.

suppose your query is named MyQuery, and the date field name is myDate, then you should right click myQuery component, select fields editor. If you defined all fields in it, you can find myDate field, select it, and in property list, you can double click OnGetText event in the "events" tab.

then write code like this:

procedure TForm1.myQeuryMyDateGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
         text:=DateTimetoStr(Sender.AsDatetime);
end;

If you didn't define fields in the fields editor, you should do extra works then, any problems, leave me a message;

Regards,
Wang
0
 
Monroe406Author Commented:

>>I tried this one with TStringGrid and it worked... I don't know if it works
>> with the DBGrid...

Sorry, but it does not work...TDBGrid does NOT have a OnMouseMove event.  :-(

Thanks for your hard work, though.

Wang's comment, however, worked great.
0
 
dwwangCommented:
Glad that I can help.

Regards,
Wang
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now