Visual Basic Drop Down List Default Text (Not Menu Item)
Ok first off I have tried to search for the answer to this but I'm not finding anything (even though I'm sure it's been answered before) I will admit that I'm new to Visual Basic but I have been studying and trying to learn but it's proving to be harder than I thought...
What I have is a combobox that is a drop down list so that the user can only make a selection not type in their own information.
The Issue I'm having is I want to make the combo box have a coupe of items that the user can select but before the user selects an item I want the text for the combo box display what the combo box is.
Ex.
Combobox name:
Sales Rep
User clicks the combo box
and it displays a list of names (but not the Sales rep text)
I would think that this is pretty simple but when it comes to Visual Basic I have learned that this is not always the case...
Thanks in advance for helping a new comer to programming.
Ryan
Re: Visual Basic Drop Down List Default Text (Not Menu Item)
Quote:
I want the text for the combo box display what the combo box is.
No you don't! Trust me. Use a label if there is a genuine need for a visual indication of what a control represents.
Re: Visual Basic Drop Down List Default Text (Not Menu Item)
Quote:
Originally Posted by
dunfiddlin
No you don't! Trust me. Use a label if there is a genuine need for a visual indication of what a control represents.
Lol ok well could you explain why I don't want to just so I know.
I did figure out a solution. Here's what I ended up doing.\
Code:
Public Class mainWindow
Private Sub mainWindow_Load(sender As Object, e As EventArgs) Handles Me.Load
cbxRep.Items.Insert(0, "Sales Rep")
cbxRep.Text = "Sales Rep"
End Sub
Private Sub cbxRep_Enter(sender As Object, e As EventArgs) Handles cbxRep.Enter
cbxRep.Items.RemoveAt(0)
End Sub
Private Sub cbxRep_Leave(sender As Object, e As EventArgs) Handles cbxRep.Leave
If cbxRep.Text = "Sales Rep" Or "" Then
cbxRep.Items.Insert(0, "Sales Rep")
cbxRep.Text = "Sales Rep"
Else
cbxRep.Items.ToString()
End If
End Sub
End Class
Other than the "Sales Rep" text not returning if you don't select a Sales Persons name and than click somewhere else.
Re: Visual Basic Drop Down List Default Text (Not Menu Item)
Quote:
Lol ok well could you explain why I don't want to just so I know.
Well one reason would be that there's a member of this forum who hates it even more than me and will have a hissy fit and nobody wants to see that again! ;)
But it is a very unprofessional look and it can be irritating for the savvy user and confusing for the inexperienced user. If nothing else, it means you're spending/wasting time trying to find solutions to problems that have no obvious reason to exist in the first place. (And yes, I do know professional coders who spend all day doing just that in order to justify their continued employment but that doesn't mean you should!)