Click here to Skip to main content
15,887,344 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Need help to show text lines from .txt file in listbox Pin
Richard MacCutchan14-Dec-12 1:59
mveRichard MacCutchan14-Dec-12 1:59 
GeneralRe: Need help to show text lines from .txt file in listbox Pin
dr_iton14-Dec-12 4:21
dr_iton14-Dec-12 4:21 
GeneralRe: Need help to show text lines from .txt file in listbox Pin
Richard MacCutchan14-Dec-12 4:39
mveRichard MacCutchan14-Dec-12 4:39 
GeneralRe: Need help to show text lines from .txt file in listbox Pin
dr_iton14-Dec-12 6:10
dr_iton14-Dec-12 6:10 
Questionprocess Pin
messages13-Dec-12 19:04
messages13-Dec-12 19:04 
AnswerRe: process Pin
OriginalGriff13-Dec-12 21:49
mveOriginalGriff13-Dec-12 21:49 
QuestionThe semaphore timeout period has expired. Pin
C-P-User-313-Dec-12 8:01
C-P-User-313-Dec-12 8:01 
QuestionTextChat works fine and users are added to the list but VoiceChat doesn't work Pin
sagarDuwal13-Dec-12 7:47
sagarDuwal13-Dec-12 7:47 
AnswerRe: TextChat works fine and users are added to the list but VoiceChat doesn't work Pin
OriginalGriff13-Dec-12 8:15
mveOriginalGriff13-Dec-12 8:15 
QuestionLogin Screen Pin
txmatt13-Dec-12 5:15
txmatt13-Dec-12 5:15 
AnswerRe: Login Screen Pin
OriginalGriff13-Dec-12 5:21
mveOriginalGriff13-Dec-12 5:21 
AnswerRe: Login Screen Pin
XsenseX13-Dec-12 5:28
XsenseX13-Dec-12 5:28 
GeneralRe: Login Screen Pin
OriginalGriff13-Dec-12 5:42
mveOriginalGriff13-Dec-12 5:42 
AnswerRe: Login Screen Pin
Matt U.13-Dec-12 7:00
Matt U.13-Dec-12 7:00 
GeneralRe: Login Screen Pin
txmatt13-Dec-12 7:04
txmatt13-Dec-12 7:04 

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.