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
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.
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.
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.
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With