Link to home
Start Free TrialLog in
Avatar of FSA7
FSA7

asked on

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
Avatar of RonaldBiemans
RonaldBiemans

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
Avatar of FSA7

ASKER

Thanks a lot
If i use this option, can i assign the cost value for the rows ?
Sorry FSA7 I don't quite understand what you mean
Avatar of FSA7

ASKER

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...
Avatar of FSA7

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial