Click here to Skip to main content
15,905,028 members
Home / Discussions / C#
   

C#

 
GeneralRe: Location of Ascii table or ascii table generator Pin
jschell15-Dec-12 11:03
jschell15-Dec-12 11:03 
GeneralRe: Location of Ascii table or ascii table generator Pin
computerpublic16-Dec-12 7:37
computerpublic16-Dec-12 7:37 
GeneralRe: Location of Ascii table or ascii table generator Pin
PIEBALDconsult15-Dec-12 9:02
mvePIEBALDconsult15-Dec-12 9:02 
GeneralRe: Location of Ascii table or ascii table generator Pin
jschell15-Dec-12 11:00
jschell15-Dec-12 11:00 
GeneralRe: Location of Ascii table or ascii table generator Pin
PIEBALDconsult15-Dec-12 15:54
mvePIEBALDconsult15-Dec-12 15:54 
QuestioniTunes Playlists in Folders Pin
trgz14-Dec-12 5:08
trgz14-Dec-12 5:08 
Questiongris view and sql id (have to set without GUI) Pin
GugliMugli14-Dec-12 4:53
GugliMugli14-Dec-12 4:53 
AnswerRe: gris view and sql id (have to set without GUI) Pin
chester_it2114-Dec-12 21:22
chester_it2114-Dec-12 21:22 
GeneralRe: gris view and sql id (have to set without GUI) Pin
GugliMugli15-Dec-12 20:23
GugliMugli15-Dec-12 20:23 
GeneralRe: gris view and sql id (have to set without GUI) Pin
chester_it2116-Dec-12 8:31
chester_it2116-Dec-12 8:31 
GeneralRe: gris view and sql id (have to set without GUI) Pin
chester_it2116-Dec-12 8:45
chester_it2116-Dec-12 8:45 
GeneralRe: gris view and sql id (have to set without GUI) Pin
GugliMugli16-Dec-12 19:12
GugliMugli16-Dec-12 19:12 
QuestionNeed to design circular track bar in c# Pin
Member 944819414-Dec-12 2:23
Member 944819414-Dec-12 2:23 
AnswerRe: Need to design circular track bar in c# Pin
Alan Balkany14-Dec-12 4:42
Alan Balkany14-Dec-12 4:42 
QuestionStart method Pin
messages14-Dec-12 2:17
messages14-Dec-12 2:17 
AnswerRe: Start method Pin
Simon_Whale14-Dec-12 3:54
Simon_Whale14-Dec-12 3:54 
GeneralRe: Start method Pin
messages14-Dec-12 5:05
messages14-Dec-12 5:05 
GeneralRe: Start method Pin
Simon_Whale14-Dec-12 5:14
Simon_Whale14-Dec-12 5:14 
GeneralRe: Start method Pin
messages14-Dec-12 6:11
messages14-Dec-12 6:11 
QuestionPrinting BST Pin
KeithF14-Dec-12 1:52
KeithF14-Dec-12 1:52 
AnswerRe: Printing BST Pin
Alan Balkany14-Dec-12 4:47
Alan Balkany14-Dec-12 4:47 
GeneralRe: Printing BST Pin
April Fans22-Dec-12 21:41
April Fans22-Dec-12 21:41 
QuestionNeed help to show text lines from .txt file in listbox Pin
dr_iton13-Dec-12 22:41
dr_iton13-Dec-12 22:41 
I created a text file using StreamWriter in a Form Application.

I can't put a code to show the lines from a text file in a listbox.
How to fix this problem.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AplikacioniStudentet
{
    public partial class FormaStudentet : Form
    {
        public FormaStudentet()
        {
            InitializeComponent();
           
        }

        private void Form1_Load(object sender, EventArgs e)
      
        {

        }

        private void textBoxID_TextChanged(object sender, EventArgs e)
        {
            string pathi = "Studentet.txt";
            using (FileStream fs = new FileStream(pathi, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (string line in textBoxID.Lines)
                        sw.Write(line + sw.NewLine);
                    sw.Close();
                }
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string pathi = "Studentet.txt";
            using (FileStream fs = new FileStream(pathi, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine(textBoxID.Text + " " + textBoxEmri.Text + " " + textBoxMbiemri.Text + " ");
                    sw.Flush();
                    sw.Close();
                }
            }
           
            /*TextWriter tw = new StreamWriter (pathi, true);
            tw.ID = ID;
            tw.emri = emri;
            tw.mbiemri = mbiemri;


            tw.Close();*/
            
        }

        private void textBoxEmri_TextChanged(object sender, EventArgs e)
        {
            string pathi = "Studentet.txt";
            using (FileStream fs = new FileStream(pathi, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (string line in textBoxEmri.Lines)
                        sw.Write(line + sw.NewLine);
                    sw.Close();
                }
            }
        }

        private void textBoxMbiemri_TextChanged(object sender, EventArgs e)
        {
            string pathi = "Studentet.txt";
            using (FileStream fs = new FileStream(pathi, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    foreach (string line in textBoxMbiemri.Lines)
                        sw.Write(line + sw.NewLine);
                    sw.Close();
                }
            }
        }

        private void listBoxStudentat_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListBox lb = new ListBox();
            System.IO.StreamReader sr = new System.IO.StreamReader("Studentet.txt");

            while (!sr.EndOfStream)
            {
                lb.Items.Add(sr.ReadLine());
            }

            sr.Close();
           
        }
    }
}

AnswerRe: Need help to show text lines from .txt file in listbox Pin
Richard MacCutchan13-Dec-12 22:48
mveRichard MacCutchan13-Dec-12 22:48 
GeneralRe: Need help to show text lines from .txt file in listbox Pin
dr_iton14-Dec-12 0:10
dr_iton14-Dec-12 0:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.