using the ListBox class and File I/O

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!!
 
M

Morten Wennevik

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.
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Update bound ListBox 6
Access Cannot select items in listbox 1
listbox 1
Listbox Search by the second column 2
What is the best way to solve this problem 3
Problem with WPF ListBox 5
WPF ListBox Question 2
ListBox update 2

Top