将ListView保存到Properties.Settings.Default中

时间:2016-02-06 14:05:27

标签: c# listview

我已经为ListView中的LOADING和SAVING项目和子项构建了这个C#:

        private void Form1_Load(object sender, EventArgs e) {
        this.Location=Properties.Settings.Default.FormLocation;
        if (Properties.Settings.Default.AllePcer == null) {
            Properties.Settings.Default.AllePcer = new StringCollection();
        }
        var items = new ListViewItem[Properties.Settings.Default.AllePcer.Count];
        for (int i = 0; i < items.Length; i++) {
            items[i] = new ListViewItem(Properties.Settings.Default.AllePcer[i].Split('|'));
        }
        this.listView1.Items.AddRange(items);
        this.Show();
        butten_Help.Focus();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
        Properties.Settings.Default.FormLocation=this.Location;
        Properties.Settings.Default.AllePcer = new StringCollection();
        var items = new List<string>();
        foreach (ListViewItem item in this.listView1.Items) {
            List<string> subitems = new List<string>();
            foreach (ListViewItem.ListViewSubItem subitem in item.SubItems) {
                subitems.Add(subitem.Text);
            }
            items.Add(string.Join("|", subitems)); <<<<<<<<<<<<<<<<<<<<
        }
        Properties.Settings.Default.AllePcer.AddRange(items.ToArray());
        Properties.Settings.Default.Save();
    }

包含“&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;给我compilingerror:

  

无法从'System.Collections.Generic.List'转换为   '字符串[]'

我该如何纠正?

0 个答案:

没有答案