How do we force the combobox to do the dropdown upon entry

blumonde

Well-known member
Joined
Jul 26, 2005
Messages
68
Programming Experience
Beginner
Hello gentlemen,

How can we have a combobox dropdown its list automatically when entering it ?

Thanks.

blumonde
 
Last edited:
jmcilhinney said:
Just set the DroppedDown property to True in the GotFocus event handler.


Hi jmcilhinney,

Thanks. However, the mouse cursor was not functioning normally when pointing at the list.

I was thinking about doing it programmatically. Maybe it would help the mouse cursor.

Thanks again.

blumonde
 
The mouse cursor is working exactly as it always does. What happens is that when the list drops down, the cursor for the form stays exactly as it was at the moment the list dropped down until the list rolls up again. When you click the ComboBox the cursor is an arrow, and so you don't want it to change so it's not a problem. The way around this is to move the cursor to the ComboBox button, set the pointer image, drop down the list, and then move the cursor back to where it was if you want to.
VB.NET:
	Private Sub ComboBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
		'Get the current cursor position.
		Dim currentCursorPosition As Point = Cursor.Position

		'Move the cursor to the combo box drop down button and set the cursor image.
		Cursor.Position = Me.ComboBox1.PointToScreen(New Point(Me.ComboBox1.Width - 10, 10))
		Me.ComboBox1.Cursor = Cursors.Default

		'Drop down the list.
		Me.ComboBox1.DroppedDown = True

		'Reset the cursor position.
		Cursor.Position = currentCursorPosition
	End Sub
Whether or not you do this you have another problem though. If the ComboBox does not have focus and you click it, then the GotFocus event is raised and the list drops down, and then the Click event is raised and the list rolls up again.
 
jmcilhinney said:
The mouse cursor is working exactly as it always does. What happens is that when the list drops down, the cursor for the form stays exactly as it was at the moment the list dropped down until the list rolls up again. When you click the ComboBox the cursor is an arrow, and so you don't want it to change so it's not a problem. The way around this is to move the cursor to the ComboBox button, set the pointer image, drop down the list, and then move the cursor back to where it was if you want to.
VB.NET:
	Private Sub ComboBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.GotFocus
		'Get the current cursor position.
		Dim currentCursorPosition As Point = Cursor.Position
 
		'Move the cursor to the combo box drop down button and set the cursor image.
		Cursor.Position = Me.ComboBox1.PointToScreen(New Point(Me.ComboBox1.Width - 10, 10))
		Me.ComboBox1.Cursor = Cursors.Default
 
		'Drop down the list.
		Me.ComboBox1.DroppedDown = True
 
		'Reset the cursor position.
		Cursor.Position = currentCursorPosition
	End Sub
Whether or not you do this you have another problem though. If the ComboBox does not have focus and you click it, then the GotFocus event is raised and the list drops down, and then the Click event is raised and the list rolls up again.


Hi jmcilhinney,

Thanks for the code above. It works much better with that proc. I thought it was a vb.net bug. I can live with that click even thing. It is better than clicking on the down arrow and then scrolling through the items anyway.

Thannks again.

Cheers,

blumonde
 
Another idea (Which I found useful)

I found that using the
VB.NET:
.DroppedDown = True
coupled with the
VB.NET:
Cursor.Current = Cursors.Default
will produce the desired effect.

My problem was that I had the user type criteria for a search into the combo box, and then populated the box with the results and droped it down. As stated above, the combo box will hold the last cursor until it is rolled back up. So, when the user was typing, the cursor will hide itself. So by calling the
VB.NET:
Cursor.Current = Cursors.Default
Code, the mouse cursor will re-appear allowing the user to make a selection from the list!
 
JByro1 said:
I found that using the
VB.NET:
.DroppedDown = True
coupled with the
VB.NET:
Cursor.Current = Cursors.Default
will produce the desired effect.

My problem was that I had the user type criteria for a search into the combo box, and then populated the box with the results and droped it down. As stated above, the combo box will hold the last cursor until it is rolled back up. So, when the user was typing, the cursor will hide itself. So by calling the
VB.NET:
Cursor.Current = Cursors.Default
Code, the mouse cursor will re-appear allowing the user to make a selection from the list!

Thank you for your help.

blumonde
 
Drop Down on Got Focus without code?

Is there a way to get the combo box to display it's items when someone enters the control, without typing the GotFocus() code?

I've got a million combo boxes on our forms, and I would think you could just get the box to do it with a property.

I know the .droppeddown = True property exists, but I can't find it as a property on the front side. I'm assuming it's because you want to tell the program to do it on GotFocus. But isn't there somewhere I can do that without coding some 20 odd GotFocus procedures?
 
Back
Top