开发者

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

开发者 https://www.devze.com 2022-12-25 06:55 出处:网络
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

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.开发者_JAVA技巧


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消