Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to save listview into a text file

$
0
0
I used to be able to save the listbox below to a textfile, but I don't know how to add the value of the items in the list view to the object.

For the file below. I am able to put each items into the StockPrice x, which is working well
Now I try to learn about the list view, and I want to put the item into Y, but I don't know how to declare that the right way.
If I 'm able to get the stockprice into y, then I will remove the listbox, and use the listview only.

I hope I write enough detail.
                try
                {
                    var items = stockListView.Items;
                    System.IO.StreamWriter writer = new System.IO.StreamWriter(currentFile);  // open stream for writing
                    for (int i = 0; i < stockListBox.Items.Count; i++)
                    {
                        StockPrice x = (StockPrice)stockListBox.Items[i]; // working great
                        StockPrice y = (StockPrice)stockListView.Items[i]; // this doesn't work
                        writer.Write(x.CompanyName);
                        writer.Write("|");
                        writer.Write(x.Stock);
                        writer.Write("|");
                        writer.Write(x.OpeningPrice);
                        writer.Write("|");
                        writer.Write(x.HighPrice);
                        writer.Write("|");
                        writer.Write(x.LowPrice);
                        writer.Write("|");
                        writer.Write(x.ClosingPrice);
                        writer.Write("|");
                        writer.WriteLine(x.Date);
                    }
                    writer.Close();
                }

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>