Reference Listview subitem by name. Think of item as an OBJECT then do this sort of thing.&g
All,
I have a listview in detail view with several subitems. I give each a name and a value add them to my listview item and add my item to the list. All works well. However, When a use clicks on the item (full row selected) i want to get the value of one of these subitems using a reference to its name rather than its index value. I was assuming this was going to be a simple coding task by replacing the subitem index value (lvi.SubItems(3).Text) with the subitem name (lvi.SubItems("MySubItem").Text)...i was wrong...can anyone please help
Cheers
[566 byte] By [
shax] at [2007-12-28]
Hi,
(lvi.SubItems("MySubItem").Text)
Dim MySubItem As OBJECT
MySubitem = lvi.SubItem(3)
would become>> (lvi.SubItems(byName(MySubItem).Text ) )
This works for a textbox so try it in a listview and the sub-items you are referring to.>>
Dim myobj As Object = TextBox1TextBox1.Text="1"
' This next line gives the message>> TextBox1
MsgBox(byName(myobj)) ' Note the Function byName returns a String value so you don't have to convert it. :-)
Dim myInt As Integer
' This next line gets the item VALUE.
myInt =
CInt(myobj.text)' This next line gives the message>> TextBox1 has the value of 1
MsgBox("Object " & byName(myobj) & " has the value of " &
CStr(myInt))
Function
byName(ByVal myObj As Object) As StringDim returnVal As StringreturnVal = myObj.name
Return returnValEnd Function
Regards,
S_DS