accessing listbox item value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am just learning to program and cannot figure out what is wrong with the
following line of code. I am trying to take the value of one item from a
ListBox and assign it to a string variable. Please help. Thanks.

strExistingTime = lstTimes.Items.Item(intCounter).ToString()
 
Candace said:
I am just learning to program and cannot figure out what is wrong with the
following line of code. I am trying to take the value of one item from a
ListBox and assign it to a string variable. Please help. Thanks.

strExistingTime = lstTimes.Items.Item(intCounter).ToString()

If your listbox contains strings:

\\\
Dim ExistingTime As String
ExistingTime = DirectCast(Me.ListBoxTimes.Items(Counter), String)
///
 
Candance,


"> strExistingTime = lstTimes.Items
is forever an collection (array) of items. Therefore you have to tell wich
item it is.

However in this case simple because it is a listbox so it is probably.

strExistingTime = lstTimes.Items(intCounter).ToString()
(assuming that you are not using it bounded however with an array of items

I hope this helps,

Cor
 
I tried both of the suggested scenarios, but I am still getting an exception
error at this point in the code. This is shown in the Watch window:

lstTimes.Items.Item Argument not specified for parameter 'index' of 'Public
Property Item(index As Integer) As Object'.
 
If all you have for each item is text then this will work, how are you
loading your listbox?
 
Here is the portion of the code where I add info to the listbox:

' display new appointment in ListBoxes
lstAppointments.Items.Add(txtAppointment.Text)
lstTimes.Items.Add(dtpTime.Value.ToShortTimeString)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top