简体   繁体   English

动态地在组合框中添加项目,并且用户添加的项目应该是永久的而不使用数据库,这可能吗?

[英]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. 就像窗口窗体上有7个组合框,当应用程序运行时,用户应该能够在组合框中添加项目,而用户添加的项目应该在组合框中是永久的。

Sure, just use the Items collection: 当然,只需使用Items集合:

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. 您还可以使用ItemsSource属性将组合框绑定到要保存在其他地方的集合。 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. 如果默认情况下使用的是ASP.NET,则这些项目将保留在viewstate中,并且所选项目将保留在回发之间。 You will only need to load the combobox once. 您只需要加载一次组合框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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