[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Listbox

hello,
I have a listbox that has 5 names coming from an ini file
and a 4 labels.
when you open the program you see the labels like this

first ame: name
last name: last
email: email
phone: 123456

and the listbox like this
person1
person2
person3
person4
person5

but when I select Person3 in the listbox it doesnt show the info
in the label, how can I do this?
0
aplelois
Asked:
aplelois
  • 6
  • 4
1 Solution
 
Fernando SotoCommented:
Hi aplelois;

How is the ListBox set up, DataSource, DisplayMember, Value member?

Where is the info for the person1, ..2, - ..5 being kept?

Fernando
0
 
apleloisAuthor Commented:
how can I know that?
0
 
Fernando SotoCommented:
Hi aplelois;

OK, if you do not know that then I am assuming that you are not setting them.

Can you post the code for the ListBox events such as SelectedIndexChanged or any other code that is pertinent to what you want to do.

Fernando
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
apleloisAuthor Commented:
       Dim ts As Object
        Dim i As Integer
        Dim sContent As String
        Dim vRows, vCells As Object

        fso = CreateObject("Scripting.FileSystemObject")
        ts = fso.OpenTextFile("Accounts.ini")
        sContent = ts.ReadAll
        ts.Close()

        vRows = Split(sContent, vbCrLf)
        For i = 0 To UBound(vRows)
            vCells = Split(vRows(i), ";")
            If UBound(vCells) >= 4 Then lstAccounts.Items.Add((vCells(4)))
        Next
        If lstAccounts.Items.Count > 0 Then lstAccounts.SelectedIndex = 0
0
 
Fernando SotoCommented:
Hi aplelois;

It looks from the above code that you are not saving the info from the Accounts.ini file except for the 5th element of the vCells array. So there is no way to fill in the text boxes with the info. So this is what I would do.

At class level I would add a structure and an ArrayList. Something like this:

    ' Define info to save from the ini file
    Public Structure Persons
        Public first As String
        Public last As String
        Public email As String
        Public phone As String
        Public Overrides Function ToString() As String
            Return first
        End Function
    End Structure

    ' Hold the info from the ini file
    Private arrPersons As New ArrayList

Then when you read the info from the ini file do it like this:

        Dim sContent As String
        Dim vRows() As String
        Dim vCells() As String
        Dim sr As New StreamReader("Drive:\Path\Accounts.ini")
        sContent = sr.ReadToEnd()
        sr.Close()

        vRows = Split(sContent, vbCrLf)
        For i As Integer = 0 To UBound(vRows)
            vCells = Split(vRows(i), ";")
            If UBound(vCells) >= 4 Then
                ' Create new persons  object
                Dim p As New Persons
                ' Fill persons object the index in vCells will have to match
                ' that of the format of the file you have
                p.first = vCells(1)
                p.last = vCells(2)
                p.email = vCells(3)
                p.phone = vCells(4)
                ' Persons to the ArrayList
                arrPersons.Add(p)
            End If
        Next
        ' Bind the ArrayList to the ListBox
        lstAccounts.DataSource = arrPersons
        ' Display Member
        lstAccounts.DisplayMember = "first"

        If lstAccounts.Items.Count > 0 Then lstAccounts.SelectedIndex = 0

Then in the SelectedIndexChanged event of the ListBox do the following:

    Private Sub lstAccounts_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles lstAccounts.SelectedIndexChanged

        ' TextBox names will need to match yours
        txtFirst.Text = CType(arrPersons(lstAccounts.SelectedIndex), Persons).first
        txtLast.Text = CType(arrPersons(lstAccounts.SelectedIndex), Persons).last
        txtEmail.Text = CType(arrPersons(lstAccounts.SelectedIndex), Persons).email
        txtPhone.Text = CType(arrPersons(lstAccounts.SelectedIndex), Persons).phone

    End Sub


Fernando
0
 
SanclerCommented:
aplelois & Fernando

This question and

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21831990.html

look to be linked.  So what is eventually done in the other may impact on this.  Something to bear in mind.

Roger
0
 
Fernando SotoCommented:
Thanks Roger. :=)
0
 
apleloisAuthor Commented:
Error      1      Type 'StreamReader' is not defined.
0
 
Fernando SotoCommented:
Add this to the top of the code file:

Imports System.IO

Fernando
0
 
apleloisAuthor Commented:
error
0
 
Fernando SotoCommented:
Post code file
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now