Can I edit the TDateTime Picker to add a button below 'Today' and 'Clear'?

I have date fields that do not apply to some records but I do not want the users NOT entering anything in because it just looks like it was just skipped. Is it possible to add a button to the datetime picker called 'Not Applicable' that when clicked (below the Today and Clear buttons) would post a fake date '1/1/1900' to the field and the field then shows all values where date = 1/1/1900 show it as 'Not Applicable' in both the field and in the grid?
Norm-alNetwork EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
The TDateTimePicker is really just a wrapper for the Windows common control.
JVCL has one but written from the ground up, to my dismay as well as hundreds of others, you can't just pick out one or two controls from JVCL to install. You have to install the entire package.

You may try one here to see if you can find a free one with source to modify yourself:
http://www.torry.net/pages.php?id=297
0
developmentguruPresidentCommented:
In the grid you can easily add a custom button that would be beside the drop down that shows the date combo.  This should be the easiest way to add the button you are looking for.  As for displaying the date as either date or possibly 'Not Applicable'... that I would have to experiment with.  

You can look in the Columns property of your grid and find the column for your date field.  There is a property in the column called ButtonStyle.  You can set this to cbsEllipsis to give the field an ellipsis field that you can respond to using OnButton Click, just be sure to check if the current column is the one you are targeting.  The date picker can be placed on a dialog that you would have full control of (just another Delphi form).  This form could be used as a drop down but this is a much more difficult process.  I would recommend at least starting with it as a dialog.  Then, if you like the results and want to make it a drop down, open a new question on how to do that.

In the field (on the dataset) there is an event called 'OnGetText'.  You can use this method to change what text will be displayed, just before it is displayed.  I would use this to spoof your 'Not Applicable' date.  Trying to use this in combination with the normal date picker may cause issues though... depends on whether or not the date is passed as a date.  Even then it would want to show it as 1/1/1900.

Let me know if you need more.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerCommented:
In addition, the dropdown is actually a TMonthCalendar. mullet_attack wrote some code way back in 2000 showing a fully operational TMonthCalendar replacement:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10321846.html

I'm sure you could modify it and then write your own TDateTimePicker to use this new calendar as the dropdown.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Eddie ShipmanAll-around developerCommented:
developmentguru, who said anything about a grid?

BTW, I have modified DateTimePicker code to show something different for a null date. I'll try to locate it.
0
developmentguruPresidentCommented:
The original poster did LOL
0
Eddie ShipmanAll-around developerCommented:
He is not editing in the grid from what I read.
0
Norm-alNetwork EngineerAuthor Commented:
SHE is displaying the 'Not Applicable' in the grid AND in the data entry form datetime field. OnGetDisplayText worked fine to show 'Not Applicable' if the date = 1/1/1900 but what I cannot do now is to show "Not Applicable" in the text of the datetime field... because incompatible type of string and date I am thinking... is there a way to show NA in a datetime field?
0
Eddie ShipmanAll-around developerCommented:
You are using a TDateTimePicker in the data entry form, correct?

I used this code to change the display to something other than the dates. However, this particular code I have a few problems with, I don't remember, it was 6 yrs ago. I don't have the full working code because I no longer work there and not sure if I have it on my home system, although I'll do a grep search to see if I can find what I'm looking for on my home system and post it if I find it.

My suggestion is to begin looking at the messages being sent to the DTP.


procedure TCSDateTimeEdit.CheckValue;
var
  LResult: Boolean;
begin
  // Only change the format at run-time!
  if ( not (csDesigning in ComponentState) ) then
  begin
    LResult := ((Kind = dtkDate) and (Trunc(DateTime) = Trunc(HighDate))
or
              ((Kind = dtkTime) and WithinDelta(DateTime, HighDate)));
    if LResult then
    begin
      SendMessage(Handle, DTM_SETFORMAT, 0, Integer(PChar('''' +
FHighText + '''')));
    end
    else
    begin
      LResult := ((Kind = dtkDate) and (Trunc(DateTime) = Trunc
(LowDate)) or
                ((Kind = dtkTime) and WithinDelta(DateTime, LowDate)));
      if LResult then
      begin
        SendMessage(Handle, DTM_SETFORMAT, 0, Integer(PChar('''' +
FLowText + '''')));
      end
      else
      begin
        LResult := ((Kind = dtkDate) and (Trunc(DateTime) = Trunc
(NullDate)) or
                   ((Kind = dtkDate) and (Date = Unassigned)) or
                   ((Kind = dtkTime) and WithinDelta(DateTime,
NullDate)));
        if LResult then
        begin
          SendMessage(Handle, DTM_SETFORMAT, 0, Integer(PChar('''' +
FNullText + '''')));
        end
        else
        begin
          SendMessage(Handle, DTM_SETFORMAT, 0, Integer(PChar(Format)));
        end;
      end;
    end;
  end;
end;

Open in new window

0
Eddie ShipmanAll-around developerCommented:
BTW, the code above was from a DTP descendant, kind of like the TJvDateTimepicker from JVCL.
0
developmentguruPresidentCommented:
The TDateTimePicker, as I recall, is really focused on maintaining a valid date.  This will make it nearly impossible to force text into the control.  There are other controls that can emulate the date time picker... make it look like a date time picker without being so picky on the text in the control.  You could use part of my suggestions to pop up a form that has the calendar and the extra button you wanted (or if you want to put the extra work into it, make it drop down).  This could be as easy as placing a non-focusable button next to a read only edit field.  When the user clicks the button then the form is displayed allowing the user to select a date or click the button for 'Not Applicable'.  You may want the fields to default to make it easier on the user as well (if there is a logical default anyway).

  The TDateTimePicker is both behaving in ways you do not want (disallowing non-date text) and not behaving in ways that you do want it to (no extra button for the 'Not Applicable).  This is a good indicator that the control is not the best place to start.  Normally when I look into this kind of thing myself I try to look up the inheritance tree and find the best place to start.  I then draw from the descendants to put the behavior I want into a new child control.
0
Eddie ShipmanAll-around developerCommented:
Not really, it does accept different "formats" and I was able to force it to use a value that wasn't a date. I had to make sure, on the data storage end, that I stored a valid date, though.

I think I know where the old source is for this so I'll look tomorrow.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.