using the ListBox class and File I/O

  • Thread starter Thread starter Light
  • Start date Start date
L

Light

Hi

I am a relatively inexperienced and I need help in this, what seems to
be a simple task
I am trying to read from a text file which contains a list of peoples
names in the format 'Surname Firstname' e.g 'Mo Greene'
each line in the textfile is a name. I want to select a name, I was
thinking of using a ListBox, so I need to know how to read each line
and populate the ListBox where each entry in the listbox is 1 line in
the textfile. When a particular entry is selected in the listbox I want
to take that entry and split the Firstname and Surname and return them
in a TextBox or any other suitable component. I also need to return
information in a suitable component/window pertaining to that
particular person, for example, I select Mo Green and when I hit go it
will return Mo Greene's personal information, I do not know where I
should return this (i.e what component I hsould use to display the
information)
I would appreciate any sort of help!!!! Thanks!!
 
Hi Light,

Take a look at StreamReader.ReadLine(), and the ListBox's SelectedIndexChanged event.
That should get you started. Feel free to ask again when you get stuck.
 
Hi,

Where is the info of these persons?
The file you said only contains the name, nothing else.

this is a pseudo code ( I did not test it ) to read the file and populate
the listbox

StreamReader reader = new StreamReader( file)
string line;
while( ( line=reader.ReadLine)!= null )
theListBox.Items.Add( line);
reader.Close();



hope this help,
 
Back
Top