Delete items in Combobox

vellaima

Centurion
Joined
Jan 29, 2003
Messages
109
The combobox which I have created is bind to the dataset. When a button is clicked, for example, I would like delete all the items in the combobox but it should not affect the database. Can you please provide me with a code.
 
To expand on the above - the combobox has an items collection - choosing to clear it will empty all the items in the combo box and NOT in the underlying dataset.

It will only remain clear until you next request to fill it!
 
You'll have to remove the datasource and add each item from the database to the items collection.

Are you using a dataset or a datareader to retrieve the data for your combobox?
 
Yes, I am using the dataset to retrieve the data to my combobox. How to clear the combobox in this case. Is there anyway out. A sample code will be appreciated.
 
Well you could clear the dataset by using:

Visual Basic:
dataset1.clear()

As a dataset is disconnected from the database as long as you don't try and use the update method of the dataadapter you should be ok!!!

Or you could remove the databinding from the combo box and in order to add the items use:

Visual Basic:
Dim myDataset As Dataset
Dim myDataRow As DataRow

myDataset = nameofyourdataset1

'Now this isn't perfect as i'm doing this without any help in front of me
For Each myDataRow in mydataset
mycombobox.items.add(mydatarow("nameofdbfield")
Next

The above code may not be exactly write but the vb intellisense will help you as you go along.But it will give you the general idea.

With the dataset.clear method if you want to add the items to the combo box again you will need to refill your dataadapter.
 
Back
Top