selecting in pairs or displaying 2 rows in 2 columns

Hello,

i have a sequitial text file representing repairs budget looking like this:

kitchen
4500
diningroom
5322
living room
4567

the numbers represent the cost per project. I need to load the following file in to the form ( i am currently loading it in the listbox ).
The way i currently have it, is that the price and project represent different rows. This is uncomfortable for choosing the project from the list, as i will need to do some operations with the prices. It is also confusing for user, as he/she will not know whether to press on 4500 or kitchen to calculate the discount or additional expenses which will depend on the amount of time the project will take.

The condition is that i cannot change the text file, but --- i can change how it gets displayed in the listbox.
What i was thinking about, is iether by clicking on one of the rows, that will automatically select the 2 together or to display the 2 rows in 2 columns. And i need some help in how to create that. Also if you have any other ideas about the design please let me know.
Below is what i got so far, which loads all the rows as a separte item in the listbox.


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sfiletocheck As String = Application.StartupPath & "\inputfile.txt"

        If Not File.Exists(sfiletocheck) Then
            MessageBox.Show("Cannot find the file. Please try again !")
        Else
            Dim writefile As StreamReader
            Dim lineoftext As String

            writefile = File.OpenText(Application.StartupPath & "\inputfile.txt")

            lineoftext = writefile.ReadLine

            If lineoftext <> Nothing Then
                Do

                    Lsttext.Items.Add(lineoftext)

                    lineoftext = writefile.ReadLine
                Loop Until lineoftext Is Nothing
            End If
        End If

    End Sub
FSA7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RonaldBiemansCommented:
Hi FSA7,

Like this ?
Dim sfiletocheck As String = "c:\test.txt"

        If Not System.IO.File.Exists(sfiletocheck) Then
            MessageBox.Show("Cannot find the file. Please try again !")
        Else
            Dim writefile As System.IO.StreamReader
            Dim lineoftext1 As String
            Dim lineoftext2 As String

            writefile = System.IO.File.OpenText("c:\test.txt")

            lineoftext1 = writefile.ReadLine
            lineoftext2 = writefile.ReadLine

            If lineoftext1 <> Nothing Then
                Do

                    ListBox1.Items.Add(lineoftext1 & vbTab & lineoftext2)

                    lineoftext1 = writefile.ReadLine
                    lineoftext2 = writefile.ReadLine

                Loop Until lineoftext1 Is Nothing
            End If
        End If



although maybe it is better to use a listview with 2 columns
0
FSA7Author Commented:
Thanks a lot
If i use this option, can i assign the cost value for the rows ?
0
RonaldBiemansCommented:
Sorry FSA7 I don't quite understand what you mean
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

FSA7Author Commented:
I want in the lsttext click event to do smth like this:

Lsttext.SelectedItem = the cost of the project.

If i select kitchen ( which will be the first item in the list ) i want the value of it to be 4500 . But i want the values to be read from the text files and not manually assign each project to the cost.

I will be selecting the repair project and then dates, and after that the calculation per that period of time will give the final price for the project

let me know if i am unclear...
0
FSA7Author Commented:
What i mean is that now the list items became a string and it is hard to extract the cost value from them to use in the calculations.
0
RonaldBiemansCommented:
You can do that by creating a table and use that table as the datasource , like

Dim dt As New DataTable

    Private Sub Form18_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim sfiletocheck As String = "c:\test.txt"

        If Not System.IO.File.Exists(sfiletocheck) Then
            MessageBox.Show("Cannot find the file. Please try again !")
        Else
            Dim writefile As System.IO.StreamReader
            Dim lineoftext1 As String
            Dim lineoftext2 As String

            dt.Columns.Add("Item", GetType(System.String))
            dt.Columns.Add("Price", GetType(System.Single))

            writefile = System.IO.File.OpenText("c:\test.txt")

            lineoftext1 = writefile.ReadLine
            lineoftext2 = writefile.ReadLine

            If lineoftext1 <> Nothing Then
                Do
                    Dim dr As DataRow = dt.NewRow
                    dr.Item(0) = lineoftext1
                    dr.Item(1) = CSng(lineoftext2)
                    dt.Rows.Add(dr)
                    lineoftext1 = writefile.ReadLine
                    lineoftext2 = writefile.ReadLine

                Loop Until lineoftext1 Is Nothing
            End If
        End If

        ListBox1.DisplayMember = "Item"
        ListBox1.ValueMember = "Price"
        ListBox1.DataSource = dt
end sub

than if you do something like this, you get the value

   Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        MsgBox(ListBox1.SelectedValue)
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.