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

Saving and loading ListView items

$
0
0
Hey guys,

So I've been trying to save a listview items to a txt file - since I'm not that experienced with any known database yet -, but it seems that I did something wrong somewhere in my code and it doesn't save the date. It does create the file, but no data inside. Here is my code:
try
            {
                StringBuilder sb = new StringBuilder();
                StreamWriter sw = new StreamWriter("Log.txt");

                if (logListView.Items.Count > 0)
                {
                    foreach (ListViewItem lvi in logListView.Items)
                    {
                        foreach (ListViewItem.ListViewSubItem listViewSubItem in lvi.SubItems)
                        {
                            sb.Append(string.Format("{0}\t", listViewSubItem.Text));
                        }
                        sw.WriteLine(sb.ToString());
                    }
                    sw.WriteLine();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong, please try again!", "Error",MessageBoxButtons.OK ,MessageBoxIcon.Error);
            }



So any suggestions guys?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



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