Retrieve value from second column of selected item in a MS Access listview


From the dbl click event of a listview I retrieve the value from first column of the selected item like this: intProductId = Forms!frmInventory.lstListView1.SelectedItem.Text

This works fine, but how can i retrieve the value from the second column?
Appreciate any suggestions.
hallpettAsked:
Who is Participating?
 
Simon BallCommented:
yeah, thats what i was going to suggest next... but i cannot even get that first line working in my code.
0
 
Simon BallCommented:
not sure if there is a more direct way, I always have to iterate the items selected collection to find the relevant items,

then use column(x,y) to get to the 2nd column.

i've got some code i'll dig out a sample
0
 
TinTombStoneCommented:
intProductID = Forms!frmInventory.lstView1.Value

will give you the value of the bound column

for other columns (column 1 = 0)

strProductName = Forms!frmInventory.lstView1.Column(1)
dblProductPrice = Forms!frmInventory.lstView1.Column(2)
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Simon BallCommented:
Dim x As Integer

    For x = 0 To List7.ListCount
    
        If List7.Selected(x) Then
        
        MsgBox List7.Column(1, x) & " - " & List7.Column(2, x)
         end if

next

Open in new window


0
 
hallpettAuthor Commented:
Get an error when I try to implement both solutions:
"Object doesn't support this property or method".
Would be best if i could get TinTombStones solutions to work: "strProductName = Forms!frmInventory.lstView1.Column(1)". I'm a novice on this field but shouldn't we somehow say that it's the selected item we want to retrieve value from?
0
 
Simon BallCommented:
did you change my list7 to lstView1?

Dim x As Integer

    For x = 0 To lstView1.ListCount
   
        If lstView1.Selected(x) Then
       
        MsgBox lstView1.Column(1, x) & " - " & lstView1.Column(2, x)
         end if

next
0
 
hallpettAuthor Commented:
Yes I changed to lstListView1. Could my reference be a problem (see image)?
2011-04-28-104018.jpg
0
 
Simon BallCommented:
aaah, sorry, I had wrongly assumed you were using a default ms access list control.

not used the activex listview control.

will do some research and mock up a test
0
 
Simon BallCommented:
ListView0.SelectedItems(0).SubItems(1).Text should work according to vb forums:

http://www.vbforums.com/showthread.php?t=573387

but its not working in my mockup...

the listview0 does not have a selected items collection...
0
 
Simon BallCommented:
i cannot even get it to work to pick up the main selection

Forms!Form1!ListView0.SelectedItems.Text gives me an error.

i tried amending the multiselect, hide selection and fullrowselect options too, to no avail.

i think we need someone who knows how to use this control successfully to help...
0
 
hallpettAuthor Commented:
I still get error: "Object doesn't support this property or method".

intProductId = Forms!frmInventory.lstListView1.SelectedItem.Text
strProductName=Forms!frmInventory.lstListView1.SelectedItems(0).SubItems(1).Text

The first of this two lines of code workes and i get the ProductId, but second line gives error. Since I have the ProductId I think I just have to write  me a small function to get the ProductName directly from the table instead. Thanks for the effort!  
0
 
hallpettAuthor Commented:
We did not find the solution I was looking for, but problem can be solved with the proposed workaround.
0
 
Simon BallCommented:
nice one.

i thnik maybe its just not possible with that control.

do you have to use that list control?  if you use the ordinary access one its much easier.
0
 
hallpettAuthor Commented:
This is the solution.
If you for instance want to get the value from selected item column 3 you can use this syntaks:
intProductId = Forms!frmInventory.lstListView1.SelectedItem.SubItems(2)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.