I was able to get the ComboBox to load a list of files from a directory.
but, now i am trying to get the contents of that file output to a TextBox or richTextBox.

I am able to use this to output to another ComboBox(however, this is not what i need...):
//code for codebox to codeBox output

string[] files = System.IO.Directory.GetFiles(@"c:\scripts");

        comboBox2.Items.Clear();
        string[] lineOfContents = File.ReadAllLines(comboBox1.Text);
        foreach (var line in lineOfContents)
        {
            string[] tokens = line.Split(',');
            comboBox2.Items.Add(tokens[0]);
            //end of codebox to codebox output.

However, I can't get the entire file to go to a Textbox.
When i use <this.richTextBox1.Text = comboBox2.Text;>
it only pulls the selected line of th text from the combobox and doesnt pull all lines of the .TXT as its split into seperate lines.

Summary: I cant seem to to pull all Lines of text from the textfile listed within the combobox into a Richtextbox by using the combobox to retrieve the list of files first.

  • am I making this too complicated and just missing something very simple??

I can use radio buttons to push the contents of the file to the RichTextBox.... something about loading from combobox to TextBox is not working.

Thank you in Advance!!!

-Joe

It looks like you need to use the AppendText method of the TextBox class:

        foreach(string line in File.ReadAllLines(comboBox1.Text))
        {
            textBox1.AppendText(line.Split(',')[0]+"\n");
        }

Hi Tinstaafl, i look forward to plugging this in when i get back home. Thank you very much for your response and time taken to answer my question!

I will update soon.

Joe

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.