Hey
Just wondering if anyone knows how I can get an item text from a listbox while in another thread, when I try listbox1.items.item(1) I dont get the usual list but Gethashcode etc
Thanks in advance
Reguards
Macuiare
Printable View
Hey
Just wondering if anyone knows how I can get an item text from a listbox while in another thread, when I try listbox1.items.item(1) I dont get the usual list but Gethashcode etc
Thanks in advance
Reguards
Macuiare
Post your relevant code.
To access an object from another thread you should first create a sub or function that changes the properties of your object, then you should check whether your listbox1 requires invokation, then your thread should invoke this sub or function in the UI thread using Me.Invoke
When you retrieve an item from a ListBox it is returned as an Object reference. That's because a ListBox can contain any type of object. As such, you can only access members of the Object class unless you cast the item as its actual type, e.g.That said, if what you want is the text displayed in the ListBox then you can get that the same way no matter what the type of the items:vb.net Code:
Dim item As SomeType = DirectCast(myListBox.Items(index), SomeType)If you had read the documentation for the ListBox class then you'd have seen that for yourself. Why does it never occur to anyone to read the documentation? That's what it's for.vb.net Code:
Dim itemText As String = myListBox.GetItemText(myListBox.Items(index))
As far as the multi-threading angle goes, follow the CodeBank link in my signature and check out my post on accessing controls from worker threads.
I enjoy helping others & it helps improve my own proficiency at the same time but I have to agree with you about the above. It must be a pretty large percentage of the time where I see a post and wonder to myself why im looking up the answer for someone else instead of them doing it for themselves.
I have one little excuse for at least some people asking trivial questions - the language barrier.
An English speaking person can easily find tons of examples and documentation on any given subject, but if someone spends quite a lot of time for just formulating a question in English with a dictionary or an online translation tool this can be forgiven I think. In my country I often encounter this problem. Fortunately, the situation has been improving over the years and more documentation is available in languages other than English.
If a question & answer can be read in english here then the same can be done in a search or help file.
Perhaps...