Home All Groups Group Topic Archive Search About

Date Time Picker Question

Author
5 Jul 2005 6:56 PM
Alastair MacFarlane
Dear All,

I have added a Date Time Picker date control to a project (in fact it is
displayed when I select a specific column in a datagrid) and I would like it
to expand when it receives the focus. The code below works for a ComboBox
(substituting the hWnd value) but it does not work work with the Date Time
Picker control. Does anyone have any ideas?

Private Sub DTPicker1_GotFocus()
Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
End Sub

The event gets fired as expected but the code does not have the desired
effect.

Thanks again.

Alastair MacFarlane

p.s The code that positions the DTPicker is as follows:

Dim gridCol As MSDataGridLib.Column
Set gridCol = grdDataGrid.Columns(grdDataGrid.Col)
DTPicker1.Move grdDataGrid.Left + gridCol.Left, grdDataGrid.Top +
grdDataGrid.RowTop(grdDataGrid.Row), gridCol.Width
DTPicker1.ZOrder
DTPicker1.Visible = True
DTPicker1.SetFocus
DTPicker1.Value = gridCol.Text

Author
5 Jul 2005 7:25 PM
Rick Rothstein
Show quote Hide quote
> I have added a Date Time Picker date control to a project (in fact it
is
> displayed when I select a specific column in a datagrid) and I would
like it
> to expand when it receives the focus. The code below works for a
ComboBox
> (substituting the hWnd value) but it does not work work with the Date
Time
> Picker control. Does anyone have any ideas?
>
> Private Sub DTPicker1_GotFocus()
> Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
> End Sub
>
> The event gets fired as expected but the code does not have the
desired
> effect.

You can always use the SendKeys kludge until someone who knows posts the
API solution for you...

Private Sub DTPicker1_GotFocus()
  SendKeys "%{DOWN}"
End Sub

Rick
Author
5 Jul 2005 7:26 PM
Saga
Try this (or equivalent):


Private Sub DTPicker1_GotFocus()

  SendKeys "{F4}"

End Sub


Saga


Show quoteHide quote
"Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
news:%23xXRWNZgFHA.3512@TK2MSFTNGP10.phx.gbl...
> Dear All,
>
> I have added a Date Time Picker date control to a project (in fact it
> is displayed when I select a specific column in a datagrid) and I
> would like it to expand when it receives the focus. The code below
> works for a ComboBox (substituting the hWnd value) but it does not
> work work with the Date Time Picker control. Does anyone have any
> ideas?
>
> Private Sub DTPicker1_GotFocus()
> Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
> End Sub
>
> The event gets fired as expected but the code does not have the
> desired effect.
>
> Thanks again.
>
> Alastair MacFarlane
>
> p.s The code that positions the DTPicker is as follows:
>
> Dim gridCol As MSDataGridLib.Column
> Set gridCol = grdDataGrid.Columns(grdDataGrid.Col)
> DTPicker1.Move grdDataGrid.Left + gridCol.Left, grdDataGrid.Top +
> grdDataGrid.RowTop(grdDataGrid.Row), gridCol.Width
> DTPicker1.ZOrder
> DTPicker1.Visible = True
> DTPicker1.SetFocus
> DTPicker1.Value = gridCol.Text
>
>
>
Author
5 Jul 2005 7:35 PM
Saga
Another way...

'If placed in BAS module, remove "Private"
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long

Const WM_KEYDOWN As Long = &H100
Const VK_TAB As Long = &H9


Private Sub DTPicker1_GotFocus()

  dim RetVal as long

  RetVal = PostMessage(DTPicker1.hwnd, WM_KEYDOWN, vbKeyF4, 0)

End Sub



Show quoteHide quote
"Saga" <antiSpam@somewhere.com> wrote in message
news:OYI4BeZgFHA.3692@TK2MSFTNGP09.phx.gbl...
>
> Try this (or equivalent):
>
>
> Private Sub DTPicker1_GotFocus()
>
>  SendKeys "{F4}"
>
> End Sub
>
>
> Saga
>
>
> "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
> news:%23xXRWNZgFHA.3512@TK2MSFTNGP10.phx.gbl...
>> Dear All,
>>
>> I have added a Date Time Picker date control to a project (in fact it
>> is displayed when I select a specific column in a datagrid) and I
>> would like it to expand when it receives the focus. The code below
>> works for a ComboBox (substituting the hWnd value) but it does not
>> work work with the Date Time Picker control. Does anyone have any
>> ideas?
>>
>> Private Sub DTPicker1_GotFocus()
>> Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
>> End Sub
>>
>> The event gets fired as expected but the code does not have the
>> desired effect.
>>
>> Thanks again.
>>
>> Alastair MacFarlane
>>
>> p.s The code that positions the DTPicker is as follows:
>>
>> Dim gridCol As MSDataGridLib.Column
>> Set gridCol = grdDataGrid.Columns(grdDataGrid.Col)
>> DTPicker1.Move grdDataGrid.Left + gridCol.Left, grdDataGrid.Top +
>> grdDataGrid.RowTop(grdDataGrid.Row), gridCol.Width
>> DTPicker1.ZOrder
>> DTPicker1.Visible = True
>> DTPicker1.SetFocus
>> DTPicker1.Value = gridCol.Text
>>
>>
>>
>
>
Author
5 Jul 2005 7:47 PM
Alastair MacFarlane
Saga,

Thanks again. This worked! Excellent. Thank you but can you explain why
posting a message would work whereas sending a message wouldn't?

Alastair MacFarlane

Show quoteHide quote
"Saga" <antiSpam@somewhere.com> wrote in message
news:ebqmBjZgFHA.1412@TK2MSFTNGP09.phx.gbl...
> Another way...
>
> 'If placed in BAS module, remove "Private"
> Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
> (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
> lParam As Long) As Long
>
> Const WM_KEYDOWN As Long = &H100
> Const VK_TAB As Long = &H9
>
>
> Private Sub DTPicker1_GotFocus()
>
>  dim RetVal as long
>
>  RetVal = PostMessage(DTPicker1.hwnd, WM_KEYDOWN, vbKeyF4, 0)
>
> End Sub
>
>
>
> "Saga" <antiSpam@somewhere.com> wrote in message
> news:OYI4BeZgFHA.3692@TK2MSFTNGP09.phx.gbl...
>>
>> Try this (or equivalent):
>>
>>
>> Private Sub DTPicker1_GotFocus()
>>
>>  SendKeys "{F4}"
>>
>> End Sub
>>
>>
>> Saga
>>
>>
>> "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
>> news:%23xXRWNZgFHA.3512@TK2MSFTNGP10.phx.gbl...
>>> Dear All,
>>>
>>> I have added a Date Time Picker date control to a project (in fact it is
>>> displayed when I select a specific column in a datagrid) and I would
>>> like it to expand when it receives the focus. The code below works for a
>>> ComboBox (substituting the hWnd value) but it does not work work with
>>> the Date Time Picker control. Does anyone have any ideas?
>>>
>>> Private Sub DTPicker1_GotFocus()
>>> Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
>>> End Sub
>>>
>>> The event gets fired as expected but the code does not have the desired
>>> effect.
>>>
>>> Thanks again.
>>>
>>> Alastair MacFarlane
>>>
>>> p.s The code that positions the DTPicker is as follows:
>>>
>>> Dim gridCol As MSDataGridLib.Column
>>> Set gridCol = grdDataGrid.Columns(grdDataGrid.Col)
>>> DTPicker1.Move grdDataGrid.Left + gridCol.Left, grdDataGrid.Top +
>>> grdDataGrid.RowTop(grdDataGrid.Row), gridCol.Width
>>> DTPicker1.ZOrder
>>> DTPicker1.Visible = True
>>> DTPicker1.SetFocus
>>> DTPicker1.Value = gridCol.Text
>>>
>>>
>>>
>>
>>
>
>
Author
5 Jul 2005 7:53 PM
Saga
There is a subtle difference between the two <g>:

The PostMessage function places (posts) a message in the message queue
associated with the thread that created the specified window and then
returns without waiting for the thread to process the message.


The SendMessage function sends the specified message to a window or
windows. The function calls the window procedure for the specified
window and does not return until the window procedure has processed the
message. The PostMessage function, in contrast, posts a message to a
thread's message queue and returns immediately.

(From http://www.mentalis.org/apilist/apilist.php)

Saga


Show quoteHide quote
"Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
news:%23Azw2pZgFHA.3124@TK2MSFTNGP12.phx.gbl...
> Saga,
>
> Thanks again. This worked! Excellent. Thank you but can you explain
> why posting a message would work whereas sending a message wouldn't?
>
> Alastair MacFarlane
>
> "Saga" <antiSpam@somewhere.com> wrote in message
> news:ebqmBjZgFHA.1412@TK2MSFTNGP09.phx.gbl...
>> Another way...
>>
>> 'If placed in BAS module, remove "Private"
>> Private Declare Function PostMessage Lib "user32" Alias
>> "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam
>> As Long, ByVal lParam As Long) As Long
>>
>> Const WM_KEYDOWN As Long = &H100
>> Const VK_TAB As Long = &H9
>>
>>
>> Private Sub DTPicker1_GotFocus()
>>
>>  dim RetVal as long
>>
>>  RetVal = PostMessage(DTPicker1.hwnd, WM_KEYDOWN, vbKeyF4, 0)
>>
>> End Sub
>>
>>
>>
>> "Saga" <antiSpam@somewhere.com> wrote in message
>> news:OYI4BeZgFHA.3692@TK2MSFTNGP09.phx.gbl...
>>>
>>> Try this (or equivalent):
>>>
>>>
>>> Private Sub DTPicker1_GotFocus()
>>>
>>>  SendKeys "{F4}"
>>>
>>> End Sub
>>>
>>>
>>> Saga
>>>
>>>
>>> "Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
>>> news:%23xXRWNZgFHA.3512@TK2MSFTNGP10.phx.gbl...
>>>> Dear All,
>>>>
>>>> I have added a Date Time Picker date control to a project (in fact
>>>> it is displayed when I select a specific column in a datagrid) and
>>>> I would like it to expand when it receives the focus. The code
>>>> below works for a ComboBox (substituting the hWnd value) but it
>>>> does not work work with the Date Time Picker control. Does anyone
>>>> have any ideas?
>>>>
>>>> Private Sub DTPicker1_GotFocus()
>>>> Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
>>>> End Sub
>>>>
>>>> The event gets fired as expected but the code does not have the
>>>> desired effect.
>>>>
>>>> Thanks again.
>>>>
>>>> Alastair MacFarlane
>>>>
>>>> p.s The code that positions the DTPicker is as follows:
>>>>
>>>> Dim gridCol As MSDataGridLib.Column
>>>> Set gridCol = grdDataGrid.Columns(grdDataGrid.Col)
>>>> DTPicker1.Move grdDataGrid.Left + gridCol.Left, grdDataGrid.Top +
>>>> grdDataGrid.RowTop(grdDataGrid.Row), gridCol.Width
>>>> DTPicker1.ZOrder
>>>> DTPicker1.Visible = True
>>>> DTPicker1.SetFocus
>>>> DTPicker1.Value = gridCol.Text
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
5 Jul 2005 8:09 PM
Jeff Johnson [MVP: VB]
"Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
news:%23Azw2pZgFHA.3124@TK2MSFTNGP12.phx.gbl...

> Thanks again. This worked! Excellent. Thank you but can you explain why
> posting a message would work whereas sending a message wouldn't?

If you're referring to sending the CB_SHOWDROPDOWN message, then the answer
is because the DateTimePicker isn't a real combo box or it's a subclassed
version that doesn't respond to that message.
Author
5 Jul 2005 7:40 PM
Alastair MacFarlane
Dear All

Thanks for the replies. I had thought about the option of using SendKeys
"%{DOWN}" first but it does not work that is why I thought of the
SendMessage API. Any other suggestions?

Thanks.

Alastair MacFarlane


Show quoteHide quote
"Alastair MacFarlane" <anonym***@microsoft.com> wrote in message
news:%23xXRWNZgFHA.3512@TK2MSFTNGP10.phx.gbl...
> Dear All,
>
> I have added a Date Time Picker date control to a project (in fact it is
> displayed when I select a specific column in a datagrid) and I would like
> it to expand when it receives the focus. The code below works for a
> ComboBox (substituting the hWnd value) but it does not work work with the
> Date Time Picker control. Does anyone have any ideas?
>
> Private Sub DTPicker1_GotFocus()
> Call SendMessage(DTPicker1.hWnd, CB_SHOWDROPDOWN, True, 0&)
> End Sub
>
> The event gets fired as expected but the code does not have the desired
> effect.
>
> Thanks again.
>
> Alastair MacFarlane
>
> p.s The code that positions the DTPicker is as follows:
>
> Dim gridCol As MSDataGridLib.Column
> Set gridCol = grdDataGrid.Columns(grdDataGrid.Col)
> DTPicker1.Move grdDataGrid.Left + gridCol.Left, grdDataGrid.Top +
> grdDataGrid.RowTop(grdDataGrid.Row), gridCol.Width
> DTPicker1.ZOrder
> DTPicker1.Visible = True
> DTPicker1.SetFocus
> DTPicker1.Value = gridCol.Text
>
>
>
Author
5 Jul 2005 7:59 PM
Rick Rothstein
> Thanks for the replies. I had thought about the option of using
SendKeys
> "%{DOWN}" first but it does not work that is why I thought of the
> SendMessage API. Any other suggestions?

Hmm! That is odd... it works on my system (WinXP Pro SP1, VB6 SP5)

Rick
Author
5 Jul 2005 8:16 PM
Alastair MacFarlane
Strange indeed. I have XP Home Sevice Pack 2 and Visual Basic with an
unknown earlier service pack. Maybe this is the issue.

Thanks for the advice.

Alastair

Show quoteHide quote
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:uaNigwZgFHA.1432@TK2MSFTNGP10.phx.gbl...
>> Thanks for the replies. I had thought about the option of using
> SendKeys
>> "%{DOWN}" first but it does not work that is why I thought of the
>> SendMessage API. Any other suggestions?
>
> Hmm! That is odd... it works on my system (WinXP Pro SP1, VB6 SP5)
>
> Rick
>
>