Why do my comboboxes display a value instead of being blank until a value is chosen from dropdown?

Posted on 2006-04-12
Last Modified: 2010-04-23
I'm rewriting a MSAccess application to VB.NET for more functionality.  I have come a long way with my understanding
but I'm puzzled with what is probably a simple fix for VB.NET novices.

I have a "Clear / New" button on a form for initializing all fields on the form in preparation for data entry of new record.
I have several combo boxes that are required fields and several that are not.  I do not want any of the combo boxes to
display a value until the user click's the dropdown and choses value.  Why do they all contain the first value from the
datatable instead of being blank...AND...more importantly, how do I clear these values until the control is chosen?

Below is my code in various parts:

Public daContacts As New System.Data.OleDb.OleDbDataAdapter
Public dsContacts As New DataSet
Public dtContacts1 As New DataTable
Public dtContacts2 As New DataTable
Public arrMrMrs() As String = {"Mr.", "Mrs.", "Ms.", "Dr."}

daContacts.SelectCommand = New System.Data.OleDb.OleDbCommand("SELECT * FROM Contacts ORDER BY ContactName", TSFConnection)
dtContacts1 = dsContacts.Tables(0)
dtContacts2 = dsContacts.Tables(0)

cmboBuyer.DataSource = dtContacts1
cmboBuyer.ValueMember = "RecID"
cmboBuyer.DisplayMember = "ContactName"

cmboSeller.DataSource = dtContacts2
cmboSeller.ValueMember = "RecID"
cmboSeller.DisplayMember = "ContactName"

cmboMrMrs.DataSource = arrMrMrs
Question by:TSFLLC
    LVL 4

    Expert Comment

    Have you tried Combobox1.Text=""

    That ought to clear it for you
    LVL 4

    Expert Comment

    oh... and one more thing... Use

            ComboBox1.Text = ""
            ComboBox1.SelectedIndex = -1 '(Meaning NO item should be selected)

    Just to make sure that nothing is selected in the Combobox1... Since It will maintain any selection even if Combobox1.Text =""

    Author Comment

    I found both of these answers previously and neither one of them worked because they are bound to a datatable.

    I did find this piece of code and it does work.
    However, I don't like it for (2) reasons:

    1) An inordinate amount of code to clear a field.
    2) An empty first record when you click on the dropdown.

    But it does work....maybe someone else has a better way.

            Dim dr As DataRow
            dr = dsContacts1.Tables(0).NewRow
            dr.Item("ContactIndex") = ""
            dsContacts1.Tables(0).Rows.InsertAt(dr, 0)

            dr = dsContacts2.Tables(0).NewRow
            dr.Item("ContactIndex") = ""
            dsContacts2.Tables(0).Rows.InsertAt(dr, 0)

            cmboSeller.SelectedIndex = 0
            cmboBuyer.SelectedIndex = 0

    In MS Access, even though you have a datasource of a SQL statement......
    It is simply a matter of cmboseller.text = "" to resolve the problem.


    Author Comment

    OOPS!   Where I wrote 'ContactIndex'....I meant 'ContactName'
    LVL 14

    Accepted Solution

    After I set a datasource, when I set the ComboBox's SelectedIndex = -1, and no value is chosen - depending on the type of ComboBox you've chosen...  If the user must select a value (DropDownStyle=DropDownList), than I don't think there's another way.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now