Can someone tell me how to add an additional item to a combobox that is bound to a datatable?
I have populated the ComboBox with data from table

        Dim ds As New DataSet

        da = New OleDb.OleDbDataAdapter(sSQLCbo, con)


        ComboBox1.DisplayMember = "Region"
        ComboBox1.ValueMember = "id"
        ComboBox1.DataSource = dt

Now I want to add an additional item "All Regions" so I can use this as part of a future query using the ComboBox SelectedIndexChanged.

Recommended Answers

All 3 Replies

U need to add the item to ur dt before setting the data and value member. or Edit ur Query to select All region as first item

Pgmer, thanks friend...

I put the following code between the Connection.Close and the ComboBox1.DisplayMember and it works fine now. Didn't like the idea of messing with my Query; seems a little sensitive at times.


        Dim dr As DataRow
        dr = dt.Rows.Add
        dr("ID") = 0
        dr("storename") = "-ALL STORES-"
        dr("storeid") = 0

        ComboBox1.DisplayMember = "Region"
        ComboBox1.ValueMember = "id"
        ComboBox1.DataSource = dt

Thanks very much, problem solved...lesson learned

Great... Happy i could help you. Some times small things wont strike in mind :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.