Sharon Kasis
Sharon Kasis

Reputation: 123

How do i add lines/strings to richTextBox1?

ListsExtractions.text1 contain 49 items But in the end richTextbox1 is empty. How can i add the strings/lines from ListsExtractions.text1 to the richTextBox1 ?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScrollLabelTest
{
    public partial class DisplayLockedThreads : Form
    {
        public DisplayLockedThreads()
        {
            InitializeComponent();

            for (int i = 0; i < ListsExtractions.text1.Count; i++)
            {
                richTextBox1.Text = ListsExtractions.text1[i];
            }
        }

        private void DisplayLockedThreads_Load(object sender, EventArgs e)
        {

        }
    }
}

ListsExtractions.text1 contain 49 items But in the end richTextbox1 is empty.

Upvotes: 0

Views: 69

Answers (2)

Microlang
Microlang

Reputation: 534

I think you are calling it twice , move from constructor to the load event your code:

   using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace ScrollLabelTest
    {
        public partial class DisplayLockedThreads : Form
        {
            public DisplayLockedThreads()
            {
                InitializeComponent();

            }

            private void DisplayLockedThreads_Load(object sender, EventArgs e)
            {
               richTextBox1.Text = String.Join(Environment.NewLine, ListsExtractions.text1 );    
            }
        }
    }

Upvotes: 1

David Pilkington
David Pilkington

Reputation: 13620

Change this

for (int i = 0; i < ListsExtractions.text1.Count; i++)
        {
            richTextBox1.Text = ListsExtractions.text1[i];
        }

to this

richTextBox1.Text = String.Join(Environment.NewLine, ListsExtractions.text1 );

Upvotes: 3

Related Questions