adding a default item in a listbox

wsyeager

Centurion
Joined
Apr 10, 2003
Messages
140
Location
Weston, FL
I'm getting the following error when trying to set a datasource property to a listbox:

"Item collection can't be modified if the Datasource property is set".

I want to add a default item to the listbox after the data is loaded, but I get the above msg:

Here is my code:

cboCustomerID.DataSource = DsCustomerID1.tblCustomerID
cboCustomerID.ValueMember = DsCustomerID1.tblCustomerID.Columns("CUSTOMER_ID").ToString
cboCustomerID.DisplayMember = DsCustomerID1.tblCustomerID.Columns("CUSTOMER_ID").ToString
cboCustomerID.Items.Insert(0, "ALL")

Does anyone know how I can add a default item to the listbox?
 
Simple Answer: Don't use the datasource

What I would do, would be loop through your DataSource and add each item using the combobox.items.add function.
 
Back
Top