Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

ComboBox question

I have a ComboBox that gets filled from the database:

cbTest.DataSource = ds.Tables(0).DefaultView

cbTest.DisplayMember = "name"
cbTest.ValueMember = "ID"

When form is loaded, the first customer returned by the query is displayed in the combo box.
I want to display a text "Select" instead.

I tried cbText.Items.Add("Select")
and cbText.Items.Insert(0,"Select") but nothing works
ASKER CERTIFIED SOLUTION
Avatar of Torrwin
Torrwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

Torrwin , I am using VB.NET not ASP.NET

In VB.NET there is no DataBind method
Avatar of YZlat

ASKER

also
 NewDR(2) = "Select..."                                    

should be

 NewDR(1) = "Select..."        

and I get invalid index error here:
   'Initially show blank row in ComboBox.
        ddlCompName.SelectedIndex = (dsTemp.Tables(0).Rows.Count) - 1
                           
Avatar of YZlat

ASKER

Ok, I've changed your code around a little and it worked:

 Dim NewDR As DataRow
        NewDR = ds.Tables(0).NewRow
        NewDR(1) = "Select One"
        ds.Tables(0).Rows.InsertAt(NewDR, 0)

        If ds.Tables(0).Rows.Count > 0 Then
            cbTest.DataSource = ds.Tables(0).DefaultView
        End If
        cbTest.DisplayMember = "name"
        cbTest.ValueMember = "ID"
I said that my code was for a web application so the syntax for you would be a little different. =P