Senne Machtelinckx Senne Machtelinckx - 12 days ago 7
C# Question

How to get value of a string out of Listview

I have a listview called lvNotities with some values in it from the class Notes.
The values in the listview come from the list: public ObservableCollection Mappen = new ObservableCollection();

public class Notes
{
public ObservableCollection<Notes> Mappen = new ObservableCollection<Notes>();
private string titel;
public string Titel
{
get { return this.titel; }
set
{
if (this.titel != value)
{
this.titel = value;
this.NotifyPropertyChanged("Titel");
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

public void NotifyPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}


For example:


  • One

  • Two

  • Three



Click code:

StreamWriter outputStream = File.CreateText(Convert.ToString(lvNotities.SelectedItem) + ".txt");


So when I double click the item, I want a document to be made with the name for example:
One.txt
or
Two.txt


But when I do it, the document is saved as :
WpfApplication.Notes


I know the explanation is bad but hopefully someone knows what I want.

Answer

Does this work?

StreamWriter outputStream = File.CreateText(((Notes)lvNotities.SelectedItem).Titel + ".txt");