是否可以在应用程序设置中保存ChecklistBox? [英] Is it possible to Save a ChecklistBox in the application settings ?
本文介绍了是否可以在应用程序设置中保存ChecklistBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在应用程序设置中保存CHECKLISTBOX(不仅是Checkbox)?
我想在加载表单时检索CheckListBox中选中的复选框吗?
Is it possible to save a CHECKLISTBOX (not only a Checkbox) in the application settings ?
I want to retreive my checkboxes checked in my CheckListBox when i load my form ?
推荐答案
好吧,我确定有很多方法,但这也许会有所帮助. >
以下所有内容均已更改为VB.Net for OP.
首先在您的设置文件中创建一个新属性
1)在解决方案资源管理器中右键单击您的项目
2)点击属性
3)单击设置选项卡
4)添加一个名为CheckedListState的新属性,并将其类型设置为string
然后使用下面的代码(修改以供您使用)
Well I am sure there are many ways but maybe this will help.
All below changed to VB.Net for the OP.
First create a new property in your settings file
1) Right click your project in the solution explorer
2) Click on properties
3) Click on settings tab
4) Add a new property called CheckedListState and set its type to string
Then use below code (modify for your use)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim checkedStates As String() = My.MySettings.Default.CheckedListState.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries)
For i As Integer = 0 To checkedStates.Length - 1
CheckedListBox1.SetItemChecked(i, Boolean.Parse(checkedStates(i)))
Next
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
My.MySettings.Default.CheckedListState = ""
For i As Integer = 0 To CheckedListBox1.Items.Count - 1
My.MySettings.Default.CheckedListState += CheckedListBox1.GetItemChecked(i).ToString() & ","
Next
My.MySettings.Default.Save()
End Sub
询问我对这段代码是否有任何疑问,我会尽力帮助您解决.
Ask me if you have any questions about this code and I will try to help you figure it out.
您不保存控件,而是保留控件的状态和值.是的,可以将其存储在您的app.config
You don''t save a control, you persist the controls state and values. Yes, it is possible to have this stored in you app.config
中,您无法保存整个控件.您可以将CheckBoxList的状态保存到应用程序中.该配置文件以XML格式存储数据,您可以从中检查CheckBox的状态是否为Checked.
这篇关于是否可以在应用程序设置中保存ChecklistBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文