Schultz’s PowerBuilder Notes

PFC DataWindow Drop Down Calendar


How come changing the date by clicking the calendar does not trigger the ItemChanged Event on idw_requestor?

Of_SetDate() in the object pfc_u_calendar is to blame. Adding the AcceptText will fix this. This line is indicated on the function below with the “<<<< ====== ADD THIS LINE =========” marker.

The PFC may have a good reason to skip the ItemChanged event, perhaps it wants to be forgiving in case the user incorrectly strikes the wrong date. But it would be nice if the object fired the ItemChanged when it closed and the value has changed.

//////////////////////////////////////////////////////////////////////////////
//
//    Function:  of_SetDate
//
//    Access:    Protected
//
//    Arguments:
//  ad_date        The date to set.
//     ab_setrequestor    Switch stating if the requestor object should get this date.
//
//    Returns:  Integer
//        1 if it succeeds and -1 if an error occurs.
//
//    Description: Sets a new date on the Visual calendar date.  If appropriate, it
//        will also set the requestor to get this new date.
//
//////////////////////////////////////////////////////////////////////////////
//
//    Revision History
//
//    Version
//    6.0   Initial version
//    7.0    Add code to always redraw for date matching 1/1/1900 to allow date
//            display for January 1900.  Previously the calendar did not redraw since
//            the initial value of the previous date was also 1/1/1900.
//
//////////////////////////////////////////////////////////////////////////////
//
//    Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//    Any distribution of the PowerBuilder Foundation Classes (PFC)
//    source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

Integer            li_rc = 1
Integer             li_month
Integer             li_year
Integer             li_day
Integer          li_FirstDayNum
String            ls_newcell
String            ls_date

// Check the argument(s).
If Not inv_datetime.of_IsValid(ad_date) Then
    Return -1
End If

// Set the new date.
id_date = ad_date

// If appropriate, set the requestor with the new date.
If ab_setrequestor Then
    // Convert the date into a string.
    ls_date = string(ad_date, is_dateformat)

    // Set the requestor with the new date.
    If IsValid(idw_requestor) Then
        idw_requestor.SetText(ls_date)
        idw_requestor.AcceptText()  <<<< ====== ADD THIS LINE   =========
    ElseIf IsValid(iem_requestor) Then
        iem_requestor.Text = ls_date
    Else
        Return -1
    End If
End If

//If appropriate, draw a new month.
If (Year(ad_date) <> Year(id_prevdate) Or Month(ad_date) <> Month(id_prevdate)) Or &
    ib_alwaysredraw Or (ad_date = date(1900, 1, 1)) Then
    of_DrawMonth(ad_date)
End If

//Initialize local values.
li_year = Year(ad_date)
li_month = Month(ad_date)
li_day = Day(ad_date)

// Unhighlight any previous cell.
If Len(Trim(is_prevcell)) > 0 Then
    If dw_cal.Modify(is_prevcell + ".border=0") <> "" Then
        li_rc = -1
    End If
End If

//Highlight the current date.
li_FirstDayNum = DayNumber(Date(li_year, li_month, 1))
ls_newcell = 'cell'+string(li_FirstDayNum + li_day - 1)
   If dw_cal.Modify(ls_newcell + ".border=5") <> "" Then
    li_rc = -1
End if

// Store the new previous infomration.
is_prevcell = ls_newcell
id_prevdate = ad_date

Return li_rc
Advertisements

June 17, 2008 - Posted by | 3. PFC, Datawindow Services | , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: