0

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.

  • 1
    Apparently, your `lvNotities.SelectedItem` is an instance of type `WpfApplication.Notes`. What member do you want to read `"One"` or `"Two"` from? Does that class override `ToString()` (or how else is `Convert.ToString` supposed to know what to return other than the class name)? – O. R. Mapper Nov 24 '16 at 13:11
  • Also, based upon your code, I'd assume your file is actually saved as `WpfApplication.Notes.txt` (i.e. with the extension), right? – O. R. Mapper Nov 24 '16 at 13:14
  • Yes it is WpfApplication.Notes.txt. And the values come from the list: public ObservableCollection Mappen = new ObservableCollection(); –  Nov 24 '16 at 13:35
  • @SenneMachtelinckx: Please mention the user name of people you are responding to (by writing `@`, followed by the user name without spaces - the website supports tab completion for this), or else the people being answered will only learn about the answer by chance. In any case, the interesting/important question is what `Notes` looks like. – O. R. Mapper Nov 24 '16 at 13:56
  • @O.R.Mapper : Didn't know that sorry. I edited my question. –  Nov 24 '16 at 14:00

2 Answers2

0

Try this...

StreamWriter outputStream = File.CreateText(Convert.ToString(((System.Windows.Controls.ContentControl)lvNotities.SelectedItem).Content) + ".txt");
Vijay
  • 663
  • 4
  • 15
0

Does this work?

StreamWriter outputStream = File.CreateText(((Notes)lvNotities.SelectedItem).Titel + ".txt");
Thejaka Maldeniya
  • 1,076
  • 1
  • 10
  • 20