|
-
Jan 3rd, 2010, 01:36 PM
#1
Thread Starter
New Member
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?
-
Jan 3rd, 2010, 08:44 PM
#2
Re: Waiting List With Arrays & Listbox
use a list(of structure) instead of an arraylist
vb Code:
Private Structure visit
Public PickUp As String
Public DropOff As String
Public Price As Decimal 'decimal ?
Public Sub New(ByVal pickup As String, ByVal dropoff As String, ByVal price As Decimal)
Me.PickUp = pickup
Me.DropOff = dropoff
Me.Price = price
End Sub
Public Overrides Function ToString() As String
Return String.Format("{0} To {1} = {2:c}", Me.PickUp, Me.DropOff, Me.Price)
End Function
End Structure
Private visitList As New List(Of visit)
then to add to the list + your listbox:
vb Code:
visitList.Add(New visit("1000am", "1030am", 10D))
listbox1.items.add(visitList(visitList.Count - 1).ToString)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 4th, 2010, 07:56 AM
#3
Thread Starter
New Member
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
-
Jan 4th, 2010, 08:01 AM
#4
Re: Waiting List With Arrays & Listbox
to add:
vb Code:
visitList.Add(New visit(txtPickUp.Text, txtDropOff.Text, cdec(txtPrice.Text)))
listbox1.items.add(visitList(visitList.Count - 1).ToString)
to remove (when you doubleclick your listbox):
vb Code:
visitList.removeat(listbox1.selectedindex)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 4th, 2010, 01:29 PM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|