[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

selecting in pairs or displaying 2 rows in 2 columns

Posted on 2004-11-04
6
Medium Priority
?
171 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:FSA7
  • 3
  • 3
6 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12492911
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
 

Author Comment

by:FSA7
ID: 12493074
Thanks a lot
If i use this option, can i assign the cost value for the rows ?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12493123
Sorry FSA7 I don't quite understand what you mean
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:FSA7
ID: 12493157
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
 

Author Comment

by:FSA7
ID: 12493233
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
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 240 total points
ID: 12493277
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question