VB combobox dropdown event

I have code in the dropdown event of the combobox to refresh the contents
of the combobox. When I click on the dropdown button of
the combobox, it drops down and closes immediately. But if
I click and hold the mouse on the dropdown button of
the combobox for about 1 second then it refreshes and drops
down.
Is there a way to stop the combobox from closing till
the contents of it is refreshed?

Thanks
[441 byte] By [vasam] at [2007-11-17 17:04:26]
# 1 Re: VB combobox dropdown event
Tried the following and saw it did not act as you said:

Private Sub Combo1_DropDown()
Dim intx As Integer
Combo1.Clear
For intx = 0 To 10
Combo1.AddItem intx
Next
Combo1.Refresh
End Sub

Private Sub Form_Load()
Dim intx As Integer
For intx = 0 To 10
Combo1.AddItem intx
Next
End Sub

Thus, you must be doing some operations in your code that I did not saw, or your control should be updated (ie: install servicepak 5)
Cimperiali at 2007-11-10 0:22:50 >
# 2 Re: VB combobox dropdown event
Thanks for your reply.

I am reloading the data in the combobox from the database and I am using SOAP call to get the data from the server and I guess there is some delay in processing those calls and the event is getting fired and it is closing it. I am not sure why. I have SP5.
vasam at 2007-11-10 0:23:53 >
# 3 Re: VB combobox dropdown event
TRy inserting a
combo1.enabled = false
...your code to retrieve data
combo1.enabled = true
Cimperiali at 2007-11-10 0:24:51 >
# 4 Re: VB combobox dropdown event
I tried setting enable property to false and then to true but that did not help. It gets disabled and populates and drops down and goes back.
vasam at 2007-11-10 0:25:59 >
# 5 Re: VB combobox dropdown event
You may try with this api:
'
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
'
This funtion will disable the drawing on your form. Try invoking it at the beginning of event like the following:
'
LockWindowUpdate me.Hwnd
'
At the end of the event, call it again this way to reenable drawings:
'
LockWindowUpdate False
'
'*******************
NOTE:
If even this sistem fails, I would suspect something is wrong in
your instructions inside the event, like if you trig twice or more
the dropdown event.
To test, simply add a static variable to the routine, and add 1 to it.
Then put the caption of your form = the variable and click
once to the combo. And look at caption of form: which value do
you read?
'************************
Cimperiali at 2007-11-10 0:26:58 >
# 6 Re: VB combobox dropdown event
Not sure if you've the solution already but as I was playing with API, I found this in MSDN:

The following four steps outline ways to use the WM_SETREDRAW message to facilitate making a number of changes to the contents of a list box in a visually pleasing manner:

Clear the redraw flag by sending the list box a WM_SETREDRAW message with wParam set to FALSE. This prevents the list box from being painted after each change.

Send appropriate messages to make any desired changes to the contents of the list box.

Set the redraw flag by sending the list box a WM_SETREDRAW message with wParam set to TRUE. The list box does not update its display in response to this message.

Call InvalidateRect(), which instructs the list box to update its display. Set the third parameter to TRUE to erase the background in the list box. If this is not done, if a short list box item is drawn over a long item, part of the long item will remain visible.

The following code fragment illustrates the process described above:

/* Step 1: Clear the redraw flag. */
SendMessage(hWndList, WM_SETREDRAW, FALSE, 0L);

/* Step 2: Add the strings. */
for (i = 0; i < n; i++)
SendMessage(hWndList, LB_ADDSTRING, ...);

/* Step 3: Set the redraw flag. */
SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);

/* Step 4: Invalidate the list box window to force repaint. */
InvalidateRect(hWndList, NULL, TRUE);

-Cool Bizs
coolbiz at 2007-11-10 0:28:00 >
# 7 Re: VB combobox dropdown event
LockWindowUpdate didn't work. It seems to lock the window and then refresh the window and the combo box again goes back.

I also tried to add a static variable to see if the event is getting fired twice. But it is firing just once. Everytime I click on the combo dropdown it increments by one.
vasam at 2007-11-10 0:28:55 >
# 8 Re: VB combobox dropdown event
I am using soap toolkit and calling a method in the server from VB client. In the form, I have a combo box and on the dropdown event of that combo box I am filling in the contents of the combobox by calling the method in the server using soap call.
When I execute and click on the dropdown button of the combobox it fills the combo box,drops down and retracts immediately without waiting to select the item in the combobox. But if I click on dropdown button and hold for about half second and release it, it fills the combo box and will be in the dropdown state until I select the item in the combo box before it retracts.
This code works fine if I am not using soap call and using just a com+ call but doesn't work when it is a soap call.
If anyone knows why or how to solve this please let me know it will be really helpful.

Thanks in advance
vasam at 2007-11-10 0:29:58 >