haroldjclements Posted January 18, 2005 Posted January 18, 2005 Hello, I am using a listView object to hold three columns of data pulled out of a database. What I want is the used to be able to click a line and the index and column data be available to be used within the next part of my program. I know that the listBox object has a .get_SelectedIndex() method. However the listView does not have this method. If anyone has any ideas I will be very grateful. Thanks, Harold Clements Quote
penfold69 Posted January 18, 2005 Posted January 18, 2005 The listview has, by default, the ability to 'Multi-select', so the relevant item you're interested in is held in a collection. If you have disabled multiselect, you should be able to retrieve the index using: myListView.SelectedIndices(0) I'd personally put a check to ensure that at least ONE item is selected before issuing that code, or you will end up with an IndexOutOfBoundsException.. Something like: If myListView.SelectedIndices.Count >0 then myIndex = myListView.SelectedIndices(0) ' <your code here > End If Just like that! Quote
haroldjclements Posted January 18, 2005 Author Posted January 18, 2005 Now can you get the data that resided at the index that has just been selected? Thanks again, Harold Clements Quote
pendragon Posted January 18, 2005 Posted January 18, 2005 MyListView.SelectedItems(0).Text to get info from first column and MyListView.SelectedItems(0).SubItems(ThecolumnNumber).Text to get info from other columns Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.