|
-
May 17th, 2012, 11:23 PM
#1
Retrieving Collection object from Listbox
Currently, I have a listbox lstInventory where I have loaded some database information from a .mdb file. I am able to add new records, and they all display correctly.
Yet, I can't seem to retrieve or access any of the listbox items. (Not trying to reaccess database in here, yet). I am hoping to "Edit" an existing database record by matching it to the lstInventory's selecteditem property. Unfortunately, I am not able to retrieve anything (tried traditional CType(lstInventory.selecteditem.ToString, String) approach, as well as a debug.write approach (which I can't seem to display, even with a Listener-which is another issue in itself).
Furthermore, when I check the listbox.items.count property, it prints out as a "0" [using a messagebox.show()]
I have tried searching multiple forums, but found lots of "database into listbox" threads, and the MSDN website hasn't helped me yet. Do I need to know the collection's name (what would it's name be based on ?)? Or am I not converting the object into a printable/countable quantity?
Let me know If I need to provide any more code, or am being unclear. Thanks in advance for your help!
-
May 18th, 2012, 12:38 AM
#2
Re: Retrieving Collection object from Listbox
How are you populating the listbox?
Do you see the data in the listbox?
Always use [code][/code] tags when posting code.
-
May 18th, 2012, 02:15 AM
#3
Re: Retrieving Collection object from Listbox
I'm populating the listbox with a loop:
Do While db.moreRecords
lstInventory.Items.Add(db.getField("ItemNum") & ", " & db.getField("Description"))
Loop
db refers to a class object that I've been using for a few past projects (errors in it are unlikely), and moreRecords is a boolean value. the getField("ItemNum") and "Description" calls pull the data from the dataset (access file).
I can see the listbox is loaded, with the initial data on the .mdb file, and with records that I was able to generate (through a separate form).
-
May 29th, 2012, 06:41 PM
#4
Re: Retrieving Collection object from Listbox
What type of object does getField return ?
-
May 29th, 2012, 07:45 PM
#5
Re: Retrieving Collection object from Listbox
What do you get if you try something like
Code:
MessageBox.Show(lstInventory.Items.Item(0).ToString)
Is it possible that a null value is being written to the list?
Always use [code][/code] tags when posting code.
-
May 30th, 2012, 12:05 PM
#6
Re: Retrieving Collection object from Listbox
I resolved this issue a bit ago, and sorry for not posting this earlier, but it almost seemed to fix itself.
I stopped using the CType(), and it worked fine for the most part (other problem came up with retrieving from another form, but was also resolved).
Niya- getField returns a string
DataMiser- I think you're right, although I can't seem to replicate the problem now. (Which may indicate I had a problem elsewhere in the coding that got fixed without me being aware)
Thanks for the help, though! It helps me understand VB a little bit more each time.
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
|