|
-
Apr 3rd, 2018, 08:15 PM
#1
Thread Starter
Fanatic Member
-
Apr 3rd, 2018, 08:34 PM
#2
Re: Combobox display properties
I just found a simple way...
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.DataSource = New String() {"one", "two", "three"}
'change text
ComboBox1.SelectedIndex = -1
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex = -1 Then
'if nothing selected, display "Department"
ComboBox1.Text = "Department"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'change text
ComboBox1.SelectedIndex = -1
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 3rd, 2018, 08:42 PM
#3
Re: Combobox display properties
Is the DropDownStyle set to DropDown or DropDownList? If it's DropDown then you should be able to display text that isn't in the drop-down list but that also means that the user can type anything they want into the control. If it's DropDownList then the control can only display text from the property/column of the DataSource whose name is assigned to the DisplayMember.
Another option is to use a watermark, although this might only be possible with a ComboBox if the DropDownStyle is DropDown too.
http://www.aaronlerch.com/blog/2007/...edit-controls/
-
Apr 3rd, 2018, 09:08 PM
#4
Thread Starter
Fanatic Member
Re: Combobox display properties
JM, the property is set to DropDown. I am not at all familiar with a watermark.
Paul, setting the .SelectedIndex then setting the text property value works. Thanks.
Tags for this Thread
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
|