c# - Trying to populate textbox and listview from txt file -


i'm able save textbox text , listview items txt file using:

private void savetoolstripmenuitem_click(object sender, eventargs e)     {         if (savefiledialog1.showdialog(this) == system.windows.forms.dialogresult.ok)         {             using (streamwriter writer = new streamwriter(savefiledialog1.filename))             {                 //writer.writeline(accounttext.text);                 writer.writeline(accounttext.text);                  if (transactionlist.items.count > 0)                 {                     foreach (listviewitem item in transactionlist.items)                     {                         stringbuilder newstring = new stringbuilder();                         foreach (listviewitem.listviewsubitem listsub in item.subitems)                         {                             newstring.append(string.format("{0}\t", listsub.text));                         }                         writer.writeline(newstring.tostring());                     }                     writer.writeline();                 }             }         }     } 

however, i'm able load textbox , can't seem listview populate. here's have far:

private void opentoolstripmenuitem_click(object sender, eventargs e)     {         if (openfiledialog1.showdialog(this) == system.windows.forms.dialogresult.ok)         {             using (streamreader reader = new streamreader(openfiledialog1.filename))             {                 accounttext.text = reader.readline();                 if (transactionlist.items.count == 0)                {                    foreach (listviewitem item in transactionlist.items)                    {                        stringbuilder mystring = new stringbuilder();                        foreach (listviewitem.listviewsubitem listsub in item.subitems)                        {                            mystring.append(string.format("{0}\t", listsub.text));                        }                        reader.read();                    }                    reader.readtoend();                }             }         }     } 

any tips appreciated.

you need split string '\t' character, return string[]. add these array items listview.

string[] items = reader.readline().split('\t'); foreach (var item in items) {     var listviewitem = new listviewitem(item);     transactionlist.items.add(listviewitem);     } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -