By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

Avoid autoselect in combobox

P: n/a
Avoid autoselect in combobox

In the load procedure of a form I am filling a combobox with data from a
database. The combobox fill the data OK, but it is automatic showing the
first item of the list as the text. How can I avoid the first item in the
list to be selected as default? I want the textbox of the combo to be left
empty until the user select an item.
My Code below:

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

MyDataAdapter.SelectCommand.CommandText = "SELECT MyDescription, MyID
FROM MyTable"
MyDataAdapter.Fill(MyDataSet)
ComboBox1.DataSource = MyDataSet
ComboBox1.DisplayMember = "MyTable.MyDescription"
ComboBox1.ValueMember = "MyTable.MyID"

End Sub

T.I.Rislaa

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Try
ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf("")

"Tor Inge Rislaa" <to*************@rislaa.no> wrote in message
news:tV*******************@news4.e.nsc.no...
Avoid autoselect in combobox

In the load procedure of a form I am filling a combobox with data from a
database. The combobox fill the data OK, but it is automatic showing the
first item of the list as the text. How can I avoid the first item in the
list to be selected as default? I want the textbox of the combo to be left
empty until the user select an item.
My Code below:

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

MyDataAdapter.SelectCommand.CommandText = "SELECT MyDescription, MyID
FROM MyTable"
MyDataAdapter.Fill(MyDataSet)
ComboBox1.DataSource = MyDataSet
ComboBox1.DisplayMember = "MyTable.MyDescription"
ComboBox1.ValueMember = "MyTable.MyID"

End Sub

T.I.Rislaa

Nov 20 '05 #2

P: n/a
Thank you, It worked just the way I wanted!

T.I.Rislaa

"scorpion53061" <sc************@yahoo.com> skrev i melding
news:u2**************@TK2MSFTNGP12.phx.gbl...
Try
ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf("")

"Tor Inge Rislaa" <to*************@rislaa.no> wrote in message
news:tV*******************@news4.e.nsc.no...
Avoid autoselect in combobox

In the load procedure of a form I am filling a combobox with data from a
database. The combobox fill the data OK, but it is automatic showing the
first item of the list as the text. How can I avoid the first item in the list to be selected as default? I want the textbox of the combo to be left empty until the user select an item.
My Code below:

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

MyDataAdapter.SelectCommand.CommandText = "SELECT MyDescription, MyID FROM MyTable"
MyDataAdapter.Fill(MyDataSet)
ComboBox1.DataSource = MyDataSet
ComboBox1.DisplayMember = "MyTable.MyDescription"
ComboBox1.ValueMember = "MyTable.MyID"

End Sub

T.I.Rislaa


Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.