문제

I am skipping the first 2 lines in the file and have managed to display my text from my .txt file in my list box using the following code

 string[] lines = File.ReadAllLines(@"C:\Users\James Dunn\Documents\Visual Studio 2012\Projects\Assignment 2\Assignment 2\MyJukeBox\bin\Debug\Media\Other.txt");

        mediaLibrary[0] = genreListBox;

for (int l = 2; l < lines.Length; l++)
            {
                mediaLibrary[0].Items.Add(lines[l]);
            }
        genreListBox.Items.Add(mediaLibrary);

But this also displays ListBox[] Array underneath my list. How do I fix this?

도움이 되었습니까?

해결책

It appears genreListBox is your ListBox, and mediaLibrary is an array of list boxes. I'm not sure what you're going for here, but adding mediaLibrary to the genreListBox items will cause the behavior you're seeing (it's calling ToString() on your ListBox array).

You can probably just omit that line.

다른 팁

remove this line: genreListBox.Items.Add(mediaLibrary); or at least, this is the line that adds ListBox[] Array into your list items... if you want to add the item at [0] then do that... but without more information i'm not sure what you're trying to do...

however, if i were to add each line to a listbox, this is how you would do what you want to do:

string[] lines = File.ReadAllLines(@"C:\Users\James Dunn\Documents\Visual Studio 2012\Projects\Assignment 2\Assignment 2\MyJukeBox\bin\Debug\Media\Other.txt");

for (int l = 2; l < lines.Length; l++)
            {
                yourDropDownList.Items.Add(lines[l]);
            }
string[] lines = File.ReadAllLines(@"C:\Users\James Dunn\Documents\Visual Studio 2012\Projects\Assignment 2\Assignment 2\MyJukeBox\bin\Debug\Media\Other.txt");

genreListBox.Items.AddRange(lines);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top