Gemme ListView in Properties.Settings.Default ???
Jeg har lavet disse 2 metoder til hhv. at hente og gemme indholdet af et ListView med 2 kolonner ("Beskrivelse" og "MAC-adresse"):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();
}
Ved linien med "<<<<<<<<<<" får jeg compileringsfejl:
cannot convert from 'System.Collections.Generic.List<string>' to 'string[]'
Hvordan retter jeg dette ?