Question filtering data from selected items in ListBox

dotdotdot

Member
Joined
Oct 22, 2008
Messages
7
Programming Experience
Beginner
Hello all,

it's the newbie asking simple questions again, but hope the experts out there could give me some direction or a helping hand.

My little project is about filtering a data file. The data file contains bus routes and a list of the places it passes by.

What I want to do is, selsect the buses I want to know from my window form's ListBox or Checked List Box, and with a press of a button, the places of the selected bus routes would pop up on the textbox.

I'm reading the file linearly, and the idea is, when I read the start of the line, and matches one of the bus route selected, the rest of the line would show up.

Could anyone give me a hand or reference to existing codes?

Many thanks in advance,
T
 
Read all the file into an array with File.ReadAllLines(path)
When a search is done, scan the array witha loop. Use string.StartsWith(str) to test if the line is relevant

Write comments of your algorithm before you write code

Good luck!
 
Thanks for the suggestion. But unfortunately, I'm using filestream to access the file, because the file is very large in size.

what I actually do is, I take a number of bytes, and break them down into readable chunks. then, to filter it with the selected bus routes from the listbox.

just a quick question, the "string.StartsWith(str)" command, what would happen if I have the option of selecting more than one bus route in the ListBox?

Thanks,
T
 
Thanks for the suggestion. But unfortunately, I'm using filestream to access the file, because the file is very large in size.
Define large

what I actually do is, I take a number of bytes, and break them down into readable chunks. then, to filter it with the selected bus routes from the listbox.
If you want to leave the file on disk, no problem.. Just use a StreamReader and repeatedly ReadLine() from the file, seeing if each startswith()..

just a quick question, the "string.StartsWith(str)" command, what would happen if I have the option of selecting more than one bus route in the ListBox?

You'll have to run multiple StartsWith searches, using a loop, and loading an array or list of all permissible options. OR logic is very easy to implement:

VB.NET:
For Each seachEntry In list
  If line StartsWith searchEntry Then 
    AddLineToTextBox
    Break off this search (dont keep looking for something you already found
 
the file is about 500MB at the moment, and it could go up even more.

I'll try the code. Will let you know how it goes

Cheers,
T
 
Back
Top