Buena
Buena

Reputation: 2491

How to Add/Remove items to ComboBox Collection?

I'm trying to remove selected item from ComboBox Collection:
Items are added manually, as a Collection, in design time.
buttonClick:

cb01.Items.Remove(cb01.SelectedItem);.

This deletes the item, but next time I open the Form - the item appears again.
Must I have a database for 5-6 items ?
Please help.

Upvotes: 1

Views: 5679

Answers (2)

Mahdi Tahsildari
Mahdi Tahsildari

Reputation: 13582

You can also work with Files (existing in System.IO Namespace) if you don't want to use a database server. for 5/6 items it's not worth to use database, and in a file you can easily find the item's line and delete the line. hope it helps.

Upvotes: 1

Habib
Habib

Reputation: 223247

This cb01.Items.Remove(cb01.SelectedItem); will only remove from the combobox, not from the datasource binded to the combobox. You may remove it from the datasource and re bind the source.

If you are binding the combobox with an array in your code, then you may save the array on a persistent storage, either a database table, or XML file and upon deletion from combobox you should remove the element from the array and save the changes to the persistent storage

Upvotes: 5

Related Questions