Ekklesia Wayan Layuk
Ekklesia Wayan Layuk

Reputation: 47

Load data from file and add to textbox C#

this is my text data in .txt file

G300#Logitech#Mouse
G500#Logitech#Mouse
G1010#Logitech#Mouse

and I want to read it and place it in text box I have tried but it just show the last line I want to write all the line

this is my code:

        List<string> lines = new List<string>();


        using (TextReader tr = new StreamReader(@"databarang.dat"))
        {
            string line;
            while ((line = tr.ReadLine()) != null)
            {
                lines.Add(line);
            }

            foreach (string s in lines)
            {
                txtOutput.Text = s + "\n";
            }
        }

and this is my layout program

and how can I split the '#' and write it in text box so in the text box it must be

G300 Logitech Mouse

G500 Logitech Mouse

G1010 Logitech Mouse

Upvotes: 0

Views: 715

Answers (2)

Patrick D&#39;Souza
Patrick D&#39;Souza

Reputation: 3571

Try using

txtOutput.AppendText(s + Environment.NewLine);

You can split a string based on the hash as shown below

string[] parts = "G300#Logitech#Mouse".Split('#');

Upvotes: 1

Pradip
Pradip

Reputation: 1537

You can do as shown below.

enter image description here

This way you can be able to get the rows as you need.

Upvotes: 2

Related Questions