-
Nov 28th, 2021, 10:36 PM
#1
Thread Starter
Lively Member
Help. Can't reset ComboBox to default text.
I have a combo box on my form. The default text is "Select Type"
One of my options is not yet supported, so I display a MsgBox and then try to reset the Combo back its default, but nothing I try works.
Code:
Private Sub cbxType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxType.SelectedIndexChanged
If cbxType.SelectedIndex = 0 Then
MsgBox("Type is not yet supported.", MsgBoxStyle.Information + vbOKOnly)
cbxType.ResetText()
Exit Sub
End If
...
All this does is simply highlight the unwanted selection.
I've also tried: cbxType.SelectedIndex = -1 and cbxType.SelectedText = "Select Type", but all they do is erase the combo box text, leaving it blank. ".ResetText()", ".SelectedItem = -1" & ".Refresh" all simply highlight the unwanted selection.
What am I doing wrong? My guess is it's some sort of "recursive" issue, but I don't know where else to put the code. TIA
-
Nov 29th, 2021, 01:12 AM
#2
Re: Help. Can't reset ComboBox to default text.
Is the DropDownStyle set to DropDown or DropDownList?
-
Nov 29th, 2021, 07:41 AM
#3
Thread Starter
Lively Member
Re: Help. Can't reset ComboBox to default text.
Thx for the reply.
The style is set to "DropDown" with displayed default text.
-
Nov 29th, 2021, 06:53 PM
#4
Re: Help. Can't reset ComboBox to default text.
Do you want the user to be able enter arbitrary text or do you just want them to be able to select from the drop-down list? If the latter, you probably ought to set the DropDownStyle to DropDownList. Do you really need "Select Type" displayed? I see a lot of people do this sort of thing but it seems like a "because I can" sort of thing. Do you place instructions in a TextBox to "Enter Type" or the like? Very few people do. If the user can work out how to use a TextBox, do you really think they need instructions on how to use a ComboBox?
-
Nov 29th, 2021, 10:26 PM
#5
Thread Starter
Lively Member
Re: Help. Can't reset ComboBox to default text.
Thx for the reply.
I have a label beside the ComboBox, but a blank box with no text is not intuitive. It should at the very least show the first option. I don't need the user to be able to edit the text (only display the valid options in a drop-down.)
A setting of "DropDownList" does not display any default text, and "Simple" appears to be no different than a textbox (no dropdown.)
I don't understand why changing the ".Text" property in code doesn't change/display the default text.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|