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();
}
}
}