Massive Gap in listview after uploading .txt file (C#) -


i'm still new show listview looks like, here code:

    private void openclientfiletoolstripmenuitem_click(object sender, eventargs e)     {         try         {             openfiledialog of = new openfiledialog();             of.showdialog(this);             of.initialdirectory = "c:\\";             of.restoredirectory = true;             string file = of.filename;               system.io.streamreader sr = new system.io.streamreader(file);              listview1.items.clear();             foreach(string line in file.readlines(file))            {                listviewitem lvi = new listviewitem();                     lvi.text = sr.readline();                      lvi.subitems.add(sr.readline());                    lvi.subitems.add(sr.readline());                    lvi.subitems.add(sr.readline());                    lvi.subitems.add(sr.readline());                    lvi.subitems.add(sr.readline());                    lvi.subitems.add(sr.readline());                    lvi.subitems.add(sr.readline());                    listview1.items.add(lvi);            }            sr.dispose();         }                 catch(exception ex)         {             messagebox.show(ex.message, "error");         }     } 

so here's problem, upload file , places items should go... except 7 lines down beginning of listview , don't know why.

however... if comment out line of code says

    lvi.text = sr.readline(); 

the huge gap gone, first column skipped wont work either. doing wrong?

(also there aren't gaps in .txt file trying load listview.)

i not clear why doing both file.readline streamreader.readline. cause of error. can rectify it.

string[] lines = file.readalllines(""); for(int = 0; < lines.length; i= + 8)        {            listviewitem lvi = new listviewitem();                 lvi.text = line[i];                  lvi.subitems.add(line[i+1]);                lvi.subitems.add(line[i+2]);                lvi.subitems.add(line[i+3]);                lvi.subitems.add(line[i+4]);                lvi.subitems.add(line[i+5]);                lvi.subitems.add(line[i+6]);                lvi.subitems.add(line[i+7]);                listview1.items.add(lvi);        } 

you need error handling make fool proof.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -