Populate a Data Table with Some Data from Text File

Benemin

Member
Joined
Feb 17, 2010
Messages
12
Location
England
Programming Experience
Beginner
Here is the code that I already have:

VB.NET:
    Private Sub frmCalculateFareIssueTicket_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        Dim RouteNo As Integer = frmDriversSection.RouteNo

        With dt.Columns
            .Add("RouteNo", GetType(Integer))
            .Add("StopNo", GetType(Integer))
            .Add("StopName", GetType(String))
        End With

        For Each line In IO.File.ReadAllLines("stops.txt")
            dt.Rows.Add(line.Split(","c))
        Next

        With cmbStartStop
            .DataSource = dt
            .DisplayMember = "StopName"
            .ValueMember = "StopNo"
            .SelectedIndex = 0
        End With

        With cmbDestStop
            .DataSource = dt
            .DisplayMember = "StopName"
            .ValueMember = "StopNo"
            .SelectedIndex = 0
        End With
    End Sub

At the moment this code populates the data table with all of the data from the text file and displays the stopname in the combo boxes.

I want to be able to populate the data table with strings of data that start with a particular number. Can anyone explain or show me how to do this?

If this is too vague or you need to know more information - please do ask. ^___^
 
VB.NET:
    For Each line In IO.File.ReadAllLines("stops.txt")
        If line.StartsWith("1") then
            dt.Rows.Add(line.Split(","c))
        End If
    Next
 
Another random question.
I want to do a calculation with the data thats in the combo boxes.

For example this is a line of data from the text file:

VB.NET:
9,6,Beaufort Road Top

Beaufort Road Top is the data thats displayed in the combo box and 6 is its route number.

I want to be able to call that number by referring to the currently selected item from the combo box. Can someone show or explain to me how to do this?
 
Back
Top