Piszę program, który wymaga storowania danych, więc użyłem resources.
Po kliknięciu buttona pojawia się openfiledialog i w ten sposób pobieram nazwę i ścieżkę do wybranego pliku.
Oba stringi dodałem do klasy:
public class PatternItem
{
private string itemName;
private string itemPath;
public PatternItem(string name, string path)
{
this.itemName = name;
this.itemPath = path;
}
public string Name
{
get
{
return itemName;
}
set
{
itemName = value;
}
}
public string Path
{
get
{
return itemPath;
}
set
{
itemPath = value;
}
}
public override string ToString()
{
return itemName;
}
}
Button_click:
private void bAddCvPattern_Click(object sender, EventArgs e)
{
ResourceWriter rw = new ResourceWriter("cvpatterns.resources");
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
rw.AddResource(ofd.SafeFileName, ofd.FileName);
cbCvPatterns.Items.Add(new PatternItem(ofd.SafeFileName, ofd.FileName));
cbCvPatterns.Text=cbCvPatterns.Items[cbCvPatterns.Items.Count-1].ToString();
}
rw.Close();
}
Wszystko działa cacy, lecz teraz się głowie, jak przy loadowaniu forma przypisać te dane do comboboxa, aby raz dodane dane były w pamięci comboBoxa.
Chciałem użyć ResourceManagera, lecz przy użyciu metody GetString muszę podać nazwę stotowanego stringa. I tu jest problem. Poszukuję metody iterującej po resources, albo innej metody storowania danych. Storowanie w .txt i .xml to też opcja, ale chciałbym zrobić to za pomocą resources.