GetItemText

huhhuhhuh

Active member
Joined
Feb 28, 2006
Messages
42
Programming Experience
Beginner
VB.NET:
Dim strtemp As String = list2.GetItemText(list1.FindStringExact(surl)).ToString

I want to get the text of an item in list2 at the index of where surl was found in list1. The above code doesn't seem to be working. Any ideas?
 
Sorry, but doesn't work. For one thing, 'item' is not a member of listbox, and surl.selectedindex will never work because surl is the string I use to search listbox1.

My theory works like this, list2 gets item text based on the index number of where the item was found via findstringexact on listbox1. Findstringexact returns an integer value and I'm guessing it's the index where the item was found so please correct me if I'm wrong.

Could there be a long workaround to this? Is it possible to obtain the index of where the item was found in list1, set the selected index on list2 to that index, and then retrieve the itemtext of the selected index on list2?
 
VB.NET:
Dim temp As String
Dim inttemp As Integer
list1.SetSelected(Convert.ToInt32(list1.FindStringExact(surl)), True)
inttemp = Convert.ToInt32(list1.SelectedIndex())
list2.SetSelected(inttemp, True)
temp = list2.GetItemText(list2.SelectedItem).ToString

I've replaced the code with this block instead. Here, it sets the selected index of the first listbox to the index where the string 'surl' is found. It then assigns the index to an integer inttemp. Note all these conversion statements are just for the sake of ensuring the items get converted to integers. Lastly, it sets the selected index of list2 to the index number of the integer variable. It then retrieves the text of the selected item on list2. I've tested this code on a proper form and it works perfectly. However, when I test it in the class where I manually create listboxes(as opposed to just dragging from the toolbox) and run the app, it returns an 'Argument out of range' exception at

VB.NET:
list1.SetSelected(Convert.ToInt32(list1.FindStringExact(surl)), True)

What does this mean. All other operations and retrievals from the listboxes work fine so I doubt I've done anything wrong manually creating the listboxes(which aren't visible, I just want to take advantage of the methods like findstringexact) Why does it work perfectly in a normal form and throw the out of range exception in a class?
 
I read somewhere that you can't access listbox items unless you set some accessible property or list property or use somehting like sbWeb item I think. I couldn't find out what the article meant. Any ideas?

As of this moment, all attempts to access the list, aside from being able to FindstringExact, result in

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll
Additional information: Specified argument was out of the range of valid values.
 
Back
Top