Results 1 to 5 of 5

Thread: Waiting List With Arrays & Listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Waiting List With Arrays & Listbox

    Hello,
    I am making a project (Waiting List) where I am using arraylist(2) therefor I am entering 3 pieces of information.

    The information in the arraylist is then sent to a listbox

    lstWaiting.Items.Add(String.Format("{0} To {1} = {2:c}", _
    arraylist(0), _
    arraylist(1), _
    arraylist(2)))

    Then when the item in the listbox is double clicked it removes the information from the listbox and sends it to textboxes

    Do While lstWaiting.SelectedIndex > -1
    lstWaiting.SelectedItem = lstWaiting.Items.Item(lstWaiting.Items.Count - 1)
    lstWaiting.Items.RemoveAt(lstWaiting.SelectedIndex)
    Loop

    txtArrayPickUp.Text = arraylist(0)
    WaitPickUp = txtArrayPickUp.Text
    txtArrayDropOff.Text = arraylist(1)
    WaitDropOff = txtArrayDropOff.Text
    txtArrayPrice.Text = arraylist(2)
    WaitPrice = txtArrayPrice.Text


    Now I could empty and re use the array to add 3 more pieces of information however, what if I have to keep that first array loaded and left on the list but had to add more information into more separate arrays and once the first arraylist becomes used (deleted from listbox and entered into textbox) I can then reuse it. How could I code that? The redim would be useless because once I delete the item from the listbox the array will be deleted and reused.

    Can anyone help me out please?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Waiting List With Arrays & Listbox

    use a list(of structure) instead of an arraylist

    vb Code:
    1. Private Structure visit
    2.     Public PickUp As String
    3.     Public DropOff As String
    4.     Public Price As Decimal 'decimal ?
    5.     Public Sub New(ByVal pickup As String, ByVal dropoff As String, ByVal price As Decimal)
    6.         Me.PickUp = pickup
    7.         Me.DropOff = dropoff
    8.         Me.Price = price
    9.     End Sub
    10.     Public Overrides Function ToString() As String
    11.         Return String.Format("{0} To {1} = {2:c}", Me.PickUp, Me.DropOff, Me.Price)
    12.     End Function
    13. End Structure
    14.  
    15. Private visitList As New List(Of visit)

    then to add to the list + your listbox:

    vb Code:
    1. visitList.Add(New visit("1000am", "1030am", 10D))
    2. listbox1.items.add(visitList(visitList.Count - 1).ToString)

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Re: Waiting List With Arrays & Listbox

    Hello Paul,
    I tried that code but it didnt work.
    All it would do was repeat the text 1000 To 1030 = $10.00

    I need it so that I enter the PickUp, DropOff and Pice via textboxes
    It then places the information onto a listbox
    Then repeat the process so I will be forming a waiting list

    Next is where I will double click on one of the items in the listbox (On the waitinglist form) and have it delete from the listbox and send the PickUp, DropOff and Price to textboxes in another form using the following code on the form Im sending the information to
    txtPickUp.Text = CStr(frmWaitingList.PickUp)
    txtDropOff.Text = CStr(frmWaitingList.DropOff)
    txtPrice.Text = CStr(frmWaitingList.Price)

    So, the variables will need to remain the same on the WaitingList form
    I will need to input information into those variables as they are entered into the listbox
    and
    I will then need to be able to input the same type of information into the same variable names (holding the previous information until it is removed from the listbox and sent to textboxes) for the next line in the listbox
    and so on .. creating the waiting list to be used...

    Once the item in the listbox is double clicked the variables empty making it resuable is why I was tring to use arrays .. maybe Im wrong

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Waiting List With Arrays & Listbox

    to add:

    vb Code:
    1. visitList.Add(New visit(txtPickUp.Text, txtDropOff.Text, cdec(txtPrice.Text)))
    2. listbox1.items.add(visitList(visitList.Count - 1).ToString)

    to remove (when you doubleclick your listbox):

    vb Code:
    1. visitList.removeat(listbox1.selectedindex)

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Re: Waiting List With Arrays & Listbox

    Sorry Paul but when I double click to remove the item in the listbox and send it to the textboxes the variables PickUp , DropOff and Price are holding the same values as all the other listbox items so when It sends to the textboxes the values never change

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width