简体   繁体   中英

C# split a textfile in two different listbox where initial lines of textfile appears in listbox1 and others appears in listbox2

I am stucked with displaying a textfile in two different listbox, the textfile contains list of links, and i want that, when someone upload the list, 1st 100 lines of textfile goes to listbox1 and the 2nd 100 lines goes to listbox2.

Any help or suggestion will be highly appreciated

OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "Text Files|*.txt";
            openFileDialog1.Title = "Select a Text file";
            openFileDialog1.FileName = "";
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                string file = openFileDialog1.FileName;

                string[] text = System.IO.File.ReadAllLines(file);
                foreach (string line in text)
                {


                  listBox1.Items.Add(line);


                }
                listBox2.Items.Add(""); //

            }
            listBox1.SetSelected(0, true);
listBox2.SetSelected(0, true);
int lineNum = 1;

foreach (string line in System.IO.File.ReadAllLines(myFilePath))
{
    if (lineNum <= 100)
    {
        listBox1.Items.Add(line);
    }
    else
    {
        listBox2.Items.Add(line);
    }

    lineNum++;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM