Thread: C# Question
View Single Post
Old 03-17-2009, 11:52 PM   #4 (permalink)
WWS
 
Super Techie

Join Date: Nov 2005

Posts: 270

WWS is on a distinguished road

Default Re: C# Question

Here is some code I wrote to populate a list box from a text file but the text file is not populating when executed. At this time I am only testing out how to populate a single colum of data. Can someone tell me what I am doing wrong. Thanks.

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


namespace List Box Populate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
StreamReader objReader = new StreamReader("c:\\data.txt");
string sLine = "";

while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)

listBox1.Items.Add(sLine);
}
objReader.Close();

}
}
}
__________________
12 Gb GSkill DDR3 Tripple Channel
2 500 Gb SATA II HD
2 BluRay Burners
2 9800GTX+ in SLI
ASUS Rampage II Extreme
Intel Core i7 920 @3.8 GHz
WWS is offline