Disable the search feature of a ComboBox

S

sid

Using the following code snip in VB.net, When I start the app and
pulldown the list from the combox box it tries to make a selection.
But I don't want this feature. How do I prevent it.
Why is the first item of the list selected as soon as the pulldown
drops ?


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim i As Integer

For i = 0 To 5
Me.ComboBox1.Items.Add(Chr(65 + i) & "- " & Format(i,
"00"))
Next
Me.ComboBox1.Text = "A"

End Sub
 
M

Mr. Arnold

sid said:
Using the following code snip in VB.net, When I start the app and
pulldown the list from the combox box it tries to make a selection.
But I don't want this feature. How do I prevent it.
Why is the first item of the list selected as soon as the pulldown
drops ?


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim i As Integer

For i = 0 To 5
Me.ComboBox1.Items.Add(Chr(65 + i) & "- " & Format(i,
"00"))
Next
Me.ComboBox1.Text = "A"

Me.ComboBox1.SelectedIndex = -1 -- to deselect combobox you
may have to execute the deselect statement twice.
 
S

sid

           Me.ComboBox1.SelectedIndex = -1   -- to deselect combobox you
may have to execute the deselect statement twice.






- Show quoted text -- Hide quoted text -

- Show quoted text -

I have already tried this without any success.
The autoselection is made when the list is opened, then the text field
is populated with whatever selection is the closest match.

I want to give the user the option to browse the selections with out
actually choosing one, and then they can choose or manually type an
entry in the text field.
 
S

sid

It seems that you have set at design time the autocomplete property.










- Show quoted text -

No, I set this property to none at desing time and in the code after
the app started.

Private Sub form1_Load(ByVal sender ...
combobox1.AutocompleteMode = AutoCompleteMode.None
 
O

Onur Güzel

Using the following code snip in VB.net, When I start the app and
pulldown the list from the combox box it tries to make a selection.
But I don't want this feature. How do I prevent it.
Why is the first item of the list selected as soon as the pulldown
drops ?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

        Dim i As Integer

        For i = 0 To 5
            Me.ComboBox1.Items.Add(Chr(65 + i) & "- " & Format(i,
"00"))
        Next
        Me.ComboBox1.Text = "A"

End Sub

Probably your combobox's "DropDownStyle" property was NOT set to
"DropDownList" (Maybe it's "DropDown"). Based on my experiment, the
behaviour doesn't occur if it is a "DropDownList" combobox (No item
gets selected automatically when user clicks on Combobox).

HTH,

Onur Güzel
 
S

sid

Probably your combobox's "DropDownStyle" property was NOT set to
"DropDownList" (Maybe it's "DropDown"). Based on my experiment, the
behaviour doesn't occur if it is a "DropDownList" combobox (No item
gets selected automatically when user clicks on Combobox).

HTH,

Onur Güzel- Hide quoted text -

- Show quoted text -

Yes, but then you don't get a textbox to type in if you want to make
an entry that is not in the list.
 
O

Onur Güzel

Yes, but then you don't get a textbox to type in if you want to make
an entry that is not in the list.

Yes, i have tought that but there's no such event that's fired after
dropdown portion is displayed then we would have chance to change
selectedindex. However, in the code of comobox item population which
you posted , "A-00" gets selected automatically because you're setting
text "A" to combobox. As you want leave DropDownStyle property as
"DropDown", which allows you to edit combox text area with keyboard,
you can overcome this behaviour by adding a textbox above the
combobox, whose height will be same as combobox and width will be less
as much as combobox's drop-down arrow, then you send back the
combobox, in your form_load set text to textbox, rather than combobox:

Like:

Dim i As Integer
For i = 0 To 5
Me.ComboBox1.Items.Add _
(Chr(65 + i) & "- " & Format(i, "00"))
Next
Me.TextBox1.Text = "A"

Finally, of course you must equalise combobox selection with textbox,
if user selects any item in combobox.

Private Sub ComboBox1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
TextBox1.Text = ComboBox1.SelectedItem
End Sub

At this time you will be able to use drop-down portion of combobox but
nobody will see any selection as textbox is in the front. To describe
what i mean, look at the screenshoot which will clarify the trick:

http://img541.imageshack.us/img541/8721/resimnew.jpg

HTH,

Onur Güzel
 
S

sid

Yes, i have tought that but there's no such event that's fired after
dropdown portion is displayed then we would have chance to change
selectedindex. However, in the code of comobox item population which
you posted , "A-00" gets selected automatically because you're setting
text "A" to combobox. As you want leave DropDownStyle property as
"DropDown", which allows you to edit combox text area with keyboard,
you can overcome this behaviour by adding a textbox above the
combobox, whose height will be same as combobox and width will be less
as much as combobox's drop-down arrow, then you send back the
combobox, in your form_load set text to textbox, rather than combobox:

Like:

Dim i As Integer
For i = 0 To 5
Me.ComboBox1.Items.Add _
(Chr(65 + i) & "- " & Format(i, "00"))
Next
Me.TextBox1.Text = "A"

Finally, of course you must equalise combobox selection with textbox,
if user selects any item in combobox.

Private Sub ComboBox1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
TextBox1.Text = ComboBox1.SelectedItem
End Sub

At this time you will be able to use drop-down portion of combobox but
nobody will see any selection as textbox is in the front. To describe
what i mean, look at the screenshoot which will clarify the trick:

http://img541.imageshack.us/img541/8721/resimnew.jpg

HTH,

Onur Güzel- Hide quoted text -

- Show quoted text -

This was a good solution. I was about to start to create my own
control.
Another programmer had the idea of adding a space to the text on
'DropDown', this fools the Autocomplete by not finding a match, but
this solution was not consistent. Timing issues ...

The floating textbox worked perfectly.

Thanks
 
O

Onur Güzel

This was a good solution. I was about to start to create my own
control.
Another programmer had the idea of adding a space to the text on
'DropDown', this fools the Autocomplete by not finding a match, but
this solution was not consistent. Timing issues ...

The floating textbox worked perfectly.

Thanks

Glad it worked,

cheers,

Onur
 

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