简体   繁体   中英

Adding items in the combobox dynamically and items added by user should be permanent without using database,is possible?

Can we add the items in the combobox located on the window form dynamically ? Like there are 7 combobox on the window form and when the application is run user should be able to add the item(s) in the combobox.And items added by user should be permanent in the combobox.

Sure, just use the Items collection:

comboBox1.Items.Add(...);

And they are permanent in the way that they persist until the combo box ceases to live. If you want to retain the items through application shutdown or closing the form then you'll need to do that yourself.

You can also bind the combo box to a collection you're keeping elsewhere with the ItemsSource property. But you'll still need to take care of saving and loading the collection contents as needed.

You may want to elaborate a bit on what exactly you expect and need.

If you are using ASP.NET by default the items will persist in the viewstate and the selected item will remain between postbacks. You will only need to load the combobox once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM