Click here to Skip to main content
15,942,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the problem:

I am using Visual Studio 2010 and I have SQL Server 2005 as database, I have binded the combobox with a table column from the Dataset.
VB
 Dim a As New SqlDataAdapter("Select * from TotTab", My.Settings.Equation1ConnectionString)
            Dim ds As New DataSet
            a.Fill(ds, "tot")
With NameCand
    .DataSource = ds.Tables("tot")
    .DisplayMember = "Name"
End With

NameCand is a combobox which is binded to Name column of TotTab.

The main problem is after binding the first record of column "Name" is automatically visible on the combobox, I need the combobox visible text to be empty and use the database Column "Name" just for suggesting the names that are already in database.

May be the problem is small but I am not able to figure out where I am wrong.

If there is any other way of achieving the above goal so please suggest.

Thank You in advance.

I guess I didn't made my question Clear
I have a combobox which has all the records of Name column and the 1st record of this column is visible when i run the project,I want the default text to be empty..
Can it be done with binding or I have to remove binding to achieve the above task.
Posted
Updated 13-Dec-11 1:52am
v3

Try setting the SelectedIndex property of DropDownList to -1 or the SelectedValue. I am not sure of this one but I think that should do it.

-Eduard
 
Share this answer
 
Comments
Vinay Indoria 13-Dec-11 23:59pm    
I Though 0 was the last index we can try with combobox,but it worked..Thanks alot Eduard,i learnt something new today.
comboboxname.Selectedindex =-1 worked
Thanks again.
Private Sub BindComboBox()
ComboBox1.DataSource = DataSet1.Tables("Suppliers")
ComboBox1.DisplayMember = "ProductName"
End Sub
 
Share this answer
 
Comments
Vinay Indoria 13-Dec-11 6:29am    
Thank you for the reply,but i guess i didn't put the question in the right way..

I got the elements in the combobox from "Name" column but i don't want it to be displayed as the default text,I want the records in the dropdown list od combobox.
Vinay Indoria 13-Dec-11 6:30am    
od=of

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900