Expamding empty ComboBox problem

A

Alek Davis

I have noticed the following problem. If you try to expand the drop-down
list of a ComboBox (DropDownStyle=DropDown) with no items and immediately
attempt to click another control (displayed underneath the combo box, not
sure about other locations), nothing will happen. It takes several mouse
clicks before you are finally able to select other dialog controls. My guess
is that the combo box gets expanded, but since there are no items, the user
does not see the list box portion of it, so if the user tries to click a
check box, a button or some other control, this mouse click is obstructed by
the expanded (but not visible) list box (this is just a guess, so it may
happen for a totally different reason). This is very confusing for the
customer, because it appears like the dialog is hanging (i.e. there is no
response to the mouse clicks). Is this a known issue? Is there a workaround?

Thanks,

Alek
 
1

100

Hi Alek,
It takes two clicks.
Even though the combobox is empty it shows dorop-down list with one empty
line. If you click inside the bounderies of the list it won't get closed and
it will look like nothing happens. This list might be hard to see (for
example if you have an edit box under the combobox and both has white
background color) and this might be your problem. Look carefully for the
thin black border that the cobobox' list has (or jsut for the test change
the BackColor of the combobox).
If you don't click on the list it takes two clicks. One to close the list
and one to switch the focus.

HTH
B\rgds
100
 
A

Alek Davis

Thanks for the reply. You are right: it takes two clicks. And I kind of
understand why, but I would like to fix it because for an unexpecting user,
this may be frustrating, since the list box is totally invisible. I mean
there are no thin or thick borders, the UI stays exactly the same (I have a
caret blinking in the text field of the combo box). Also I checked the state
of the DropDown property in the DropDown event handler and it is set to
false(?!). And I do not have any other controls which would interfere with
the drop-down list. Anyway, I am thinking if I can programmatically perform
a click in the DropDown event handler (after detecting that there are no
items there), logically, it should do the trick. Not sure if it will or how
to do this, though.

Alek
 
A

Alek Davis

OK, I fixed it by doing just that: in the DropDown event handler, check if
the number of items is 0, and if so, send the mouse click event to the combo
box. If you need to do the same, here is the sample code:

using System.Runtime.InteropServices;
....
// Dialog class
class ...
{
private const UInt32 WM_LBUTTONDOWN = 0x201;
private const UInt32 WM_LBUTTONUP = 0x202;

[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr handle, UInt32 message, int
wParam, int lParam);
....
private static void SendClick(Control target)
{
if (target == null)
return;

SendMessage(target.Handle, WM_LBUTTONDOWN, 0, 0);
SendMessage(target.Handle, WM_LBUTTONUP, 0, 0);
}

private void comboBox_DropDown(object sender, System.EventArgs e)
{
if (((ComboBox)sender).Items.Count == 0)
SendClick((Control)sender);
}
....
}

Enjoy,

Alek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top