Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if combobox drop down list is revealed up or down?

I have control (implemented C#, .Net 2.0) that inherits from combobox. It has filtering and other stuff. To keep UI right, when amount of items during filtering falls, drop down list changes its size to fit the number of items left (it is done by NativeMethods.SetWindowPos(...)).

Is there any way to check if drop down list is revealed up or down (literally) - not to check if it is open, it is open, but in which direction, upwards or downwards?

cheers, jbk

like image 871
jotbek Avatar asked Feb 08 '12 11:02

jotbek


People also ask

What is the difference between a drop down and drop down list combo box?

A drop-down list is a list in which the selected item is always visible, and the others are visible on demand by clicking a drop-down button. A combo box is a combination of a standard list box or a drop-down list and an editable text box, thus allowing users to enter a value that isn't in the list.

How do I make my combobox read only?

Just change the DropDownStyle to DropDownList . Or if you want it completely read only you can set Enabled = false , or if you don't like the look of that I sometimes have two controls, one readonly textbox and one combobox and then hide the combo and show the textbox if it should be completely readonly and vice versa.


2 Answers

The ComboBox has two events (DropDown and DropDownClosed) that are fired when the dropdown part opens and closes, so you might want to attach handlers to them to monitor the state of the control.

Alternatively, there's also a boolean property (DroppedDown) which should tell you the current state.

like image 102
Andreas Baus Avatar answered Nov 10 '22 21:11

Andreas Baus


ComboBoxes open downwards or upwards depending on the space they have to open: if they have avaliable space below them they'll open downwards as usual, if not they'll open upwards.

So you simply have to check if they have space enough below them to know. Try this code:

void CmbTestDropDown(object sender, EventArgs e)
{
    Point p = this.PointToScreen(cmbTest.Location);
    int locationControl = p.Y; // location on the Y axis
    int screenHeight = Screen.GetBounds(new Point(0,0)).Bottom; // lowest point
    if ((screenHeight - locationControl) < cmbTest.DropDownHeight)
        MessageBox.Show("it'll open upwards");
    else MessageBox.Show("it'll open downwards");
}
like image 25
CMPerez Avatar answered Nov 10 '22 22:11

CMPerez