Aaron
Aaron

Reputation: 11673

How to get items from an array and display them in a textbox;

string[] files = Directory.GetFiles("C:/Users/ME/Desktop/items/", ".txt", SearchOption.AllDirectories);

How would I display the returned results in a textbox that I have created?

Upvotes: 1

Views: 109

Answers (4)

user596075
user596075

Reputation:

Provided this is a multi-line textbox:

foreach (string file in files)
{
    YourTextBox.Text += file + '\r\n';
}

Upvotes: 0

sehe
sehe

Reputation: 393064

textbox1.Text = string.Join(Environment.NewLine, files);

This internally uses a StringBuilder or equivalent for optimum performance and heap fragmentation prevention

Upvotes: 3

competent_tech
competent_tech

Reputation: 44931

System.Text.StringBuilder sbText = new System.Text.StringBuilder(10000);

foreach (string sFile in files) {
  sbText.AppendLine(sFile);
}

TextBox1.Text = sbText.ToString();

Upvotes: 0

Sam Axe
Sam Axe

Reputation: 33738

foreach (string file in files) {
  textbox1.Text += file + Environment.NewLine;
}

Upvotes: 1

Related Questions