保存列表框设置 [英] Save settings for listbox

查看:51
本文介绍了保存列表框设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签控件,对于每个标签,我都有一个列表框,文本框,添加按钮,删除按钮和保存按钮.对于每个列表框,我都会添加要在每次单击保存"按钮时保存到设置的项目,以便在加载表单时 设置被恢复.

I have a tab control and for each tab I have a listbox, textbox, add button, remove button and a save button. For each listbox I would be adding items that I would like to save to settings whenever save button is clicked so that when the form loads the settings are restored.

我为其中一个选项卡提供了此代码,但是它不起作用.在Laoding时未恢复设置:(

I have this code for one of the tabs but it doesn't work. Settings were not restored upon laoding :(

  Private Sub cmdSave_Click(发送者为对象,e作为EventArgs)处理cmdSave.Click
      选择Case True
          案例listBox.SelectedTab是tp1
                            如果是MessageBox.Show(您确定要保存1的设置吗?",保存电子邮件设置",
                             MessageBoxButtons.YesNo,MessageBoxIcon.Question)= True然后
                   如果My.Settings.list1set什么都没有,那么
               b My.Settings.list1set =新的System.Collections.Specialized.StringCollection()
                   如果结束
                   对于lstClient1.Items中的每个项目
               b My.Settings.list1set.Add(item)
                   下一个
                    My.Settings.Save()
                            如果结束
      结束选择

 Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
        Select Case True
            Case listBox.SelectedTab Is tp1
                If MessageBox.Show("Are you sure you want to save settings for 1?", "Save Email Settings",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question) = True Then
                    If My.Settings.list1set Is Nothing Then
                        My.Settings.list1set = New System.Collections.Specialized.StringCollection()
                    End If
                    For Each item In lstClient1.Items
                        My.Settings.list1set.Add(item)
                    Next
                    My.Settings.Save()
                End If
        End Select

  结束

    End Sub

  私有子Form1_Load(作为对象发送,作为EventArgs发送)处理MyBase.Load
      如果My.Settings.list1set什么都没有,那么
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If My.Settings.list1set Is Nothing Then

推荐答案

Hi

我在一个项目和功能中使用了与预期相同的设置(或多或少).

I use the same (more or less) setup in one of my projects and functions as expected.

您将需要设置一些断点,并检查变量以查看它们是否符合预期.

You will need to set some breakpoints and examine the variables to see if they are as expected.

例如,在"My.Settings.Save()"行上放置一个断点,然后查看是否到达a),b)"list1set"列表是否实际上包含任何项目.一旦验证通过,在"lstClient1.Items.Add(item)"行放置一个断点并逐步执行循环 检查是否有要添加的项目.

For example, put a breakpoint at the line 'My.Settings.Save()' and see if a) it is reached, b) does the 'list1set' list actually contain any items. Once that is verified, put a breakpoint at the line 'lstClient1.Items.Add(item)' and step through the loop checking that there are items being added.


这篇关于保存列表框设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆