Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Calendar
  New Posts New Posts RSS Feed - Date Picker Sample Problem?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Date Picker Sample Problem?

 Post Reply Post Reply
Author
Message
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post Topic: Date Picker Sample Problem?
    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
Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
John31 View Drop Down
Groupie
Groupie
Avatar

Joined: 08 December 2005
Location: United States
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote John31 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.