?
Solved

Replacing Julian date in TDBGrid cells

Posted on 1998-12-27
8
Medium Priority
?
297 Views
Last Modified: 2010-04-04
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
Comment
Question by:Monroe406
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1353302
Hello Monroe!

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

-Viktor
--Ivanov
0
 

Author Comment

by:Monroe406
ID: 1353303
>> 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
 
LVL 10

Expert Comment

by:viktornet
ID: 1353304
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Monroe406
ID: 1353305
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1353306
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
 
LVL 4

Expert Comment

by:dwwang
ID: 1353307
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
 

Author Comment

by:Monroe406
ID: 1353308

>>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
 
LVL 4

Accepted Solution

by:
dwwang earned 300 total points
ID: 1353309
Glad that I can help.

Regards,
Wang
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

801 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