Print Page | Close Window

Date Picker Sample Problem?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Calendar
Forum Description: Topics Related to Codejock Calendar
URL: http://forum.codejock.com/forum_posts.asp?TID=3960
Printed Date: 24 November 2024 at 7:57pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Date Picker Sample Problem?
Posted By: John31
Subject: Date Picker Sample Problem?
Date Posted: 07 April 2006 at 3:04pm

In the DatePickerSample (VB6) the behavior of the cmbPopUp seems wrong to me.  Specifically, if there is a date in the combo box  and you click the drop down button the date is displayed in the data picker. All good so far. If the user then clicks the drop down again the date picker closes and the value in the cmbPopUp is cleared.  I have tried all sorts of stuff so that the value in the cmbPopUp remains the same as before but I cannot get it to work.  Any ideas on how to make it retain the previous value?

 



-------------
Regards

John Layton



Replies:
Posted By: sserge
Date Posted: 08 April 2006 at 7:13am
Hi John,

It is a desired behavior. If you look into cmbPopUp_DropDown() method, you can see that combo box text is set only if something was choosen inside the date picker. If there was an outside click, or Escape button pressed, ShowModal method returns False and combo text is cleared. You can change the sample logic in any way you'd like, just note that ShowModal returns True only if user has chosen some date and False if cancelled a popup.

--
WBR,
Serge


Posted By: John31
Date Posted: 10 April 2006 at 11:07am

I am aware of the logic used in the sample.  However, take the following modification to the code which should allow for restoring the original value into the combo, but it does not work. The DatePicker is cause the value to be removed.  If you step through the code it works fine, but when you run it with no breaks the value is not restored. 

Private Sub cmbPopUp_DropDown()
    Dim sValue As String
 '   Label1.Caption = "Pop-up:"
 
    ' get the current value of the combo box
    sValue = cmbPopUp.Text
   
    If IsDate(cmbPopUp.Text) Then
        'wndDatePickerPopUp.SelectRange cmbPopUp.Text, cmbPopUp.Text
        wndDatePickerPopUp.EnsureVisible cmbPopUp.Text
    End If
   
    wndDatePickerPopUp.Left = cmbPopUp.Left
    wndDatePickerPopUp.Top = cmbPopUp.Top + cmbPopUp.Height + 20
   
    If wndDatePickerPopUp.ShowModal(1, 1) Then
   
        Dim strDate0 As String, strDate1 As String
        Dim nCount As Long
            
        nCount = wndDatePickerPopUp.Selection.BlocksCount
        If nCount > 0 Then
             cmbPopUp.Refresh
             cmbPopUp.Text = wndDatePickerPopUp.Selection.Blocks(0).DateBegin
                                        
             strDate0 = wndDatePickerPopUp.Selection.Blocks(0).DateBegin
             strDate1 = wndDatePickerPopUp.Selection.Blocks(nCount - 1).DateEnd
            
             wndLabel_PopUp.Text = strDate0 & " - " & strDate1
        Else
             wndLabel_PopUp.Text = "-none-"
             ' restore the previous value of the combo
             cmbPopUp.Text = sValue
        End If
    Else
        wndLabel_PopUp.Text = "-ESC-"
        ' restore the previous value of the combo
        cmbPopUp.Text = sValue
    End If
    PostMessage cmbPopUp.hwnd, CB_SHOWDROPDOWN, 0, 0
    cmbPopUp.Refresh
End Sub



-------------
Regards

John Layton


Posted By: sserge
Date Posted: 10 April 2006 at 2:14pm
The main idea is to restore text after exit from cmbPopUp_DropDown .
To resolve this problem I add a timer object to the form: popupTimer
Disabled by default, Timeout = 10 ms.

'NEW code:
'------------------------------------------------
Dim g_sDPpopUpCBValue As String 'to store prev value of combobox
Private Sub popupTimer_Timer()
    popupTimer.Enabled = False

    cmbPopUp.Text = g_sDPpopUpCBValue
    g_sDPpopUpCBValue = "?-?-?"
End Sub
'Changed code:
'------------------------------------------------
Private Sub cmbPopUp_DropDown()
    Dim bRestore As Boolean

    'get the current value of the combo box
    g_sDPpopUpCBValue = cmbPopUp.Text
    bRestore = False
    If IsDate(cmbPopUp.Text) Then
        wndDatePickerPopUp.EnsureVisible cmbPopUp.Text
    End If

    wndDatePickerPopUp.Left = cmbPopUp.Left
    wndDatePickerPopUp.Top = cmbPopUp.Top + cmbPopUp.Height + 20

    If wndDatePickerPopUp.ShowModal(1, 1) Then

        Dim strDate0 As String, strDate1 As String
        Dim nCount As Long

        nCount = wndDatePickerPopUp.Selection.BlocksCount
        If nCount > 0 Then
            cmbPopUp.Refresh
            cmbPopUp.Text = wndDatePickerPopUp.Selection.Blocks(0).DateBegin

            strDate0 = wndDatePickerPopUp.Selection.Blocks(0).DateBegin
            strDate1 = wndDatePickerPopUp.Selection.Blocks(nCount - 1).DateEnd

            wndLabel_PopUp.Text = strDate0 & " - " & strDate1
        Else
            wndLabel_PopUp.Text = "-none-"
            bRestore = True
        End If
    Else
        wndLabel_PopUp.Text = "-ESC-"
        bRestore = True
    End If
    PostMessage cmbPopUp.hwnd, CB_SHOWDROPDOWN, 0, 0
    cmbPopUp.Refresh

    If bRestore Then
        ' to restore the previous value of the combo
        popupTimer.Enabled = True
    End If
End Sub


--
WBR,
Serge


Posted By: John31
Date Posted: 10 April 2006 at 4:30pm

I implemented something similar to solve the problem after looking at various subclassing options. The paint of the drop down after a date is selected is very annoying.  It makes the solution look like a hack rather and does not follow the professional style of all your other controls. 

I would love to see you add a fully implemented Combo Box Date Picker as an optional control so that this type of paint issue does not occur.

Keep up the good work!

 



-------------
Regards

John Layton



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net