|
-
May 1st, 2008, 06:26 AM
#1
Thread Starter
Member
[2005] Listview Control Problem
Hey,
Is there anyway to find out the index of the last selected item in the listview?
Or on button click extract subitem(2) value from the last selectedrow in the listview. Store it as a variable. Bring a inputbox up, and insert the value entered into the listview subitem(2) field.
Thanks
-
May 1st, 2008, 12:21 PM
#2
Re: [2005] Listview Control Problem

I don't think listview has any sort of 'lastselecteditem' property. The solution would probably be some sort of hack where you save the selected item to a variable before it get's updated, assuming you can handle an event to catch the selected item before the control changes it. That will be the trick, and I don't know which one it will be.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
May 1st, 2008, 01:02 PM
#3
Re: [2005] Listview Control Problem
when you say last selected, that doesn't really clarify things.
Do you mean the last items selected when you have multiple items selected? Or do you mean when you have an item selected, then you select a different one, you want to know what the previous one was?
-
May 1st, 2008, 04:48 PM
#4
Thread Starter
Member
Re: [2005] Listview Control Problem
I was trying to do as dolot suggested and on selecteditem change event save the selected item to a variable. But I didn't know how to get the index of the item.
Kleinma:
If I select item A and then click a button that brings an inputbox up on screen (It deselects the item in the listview). so I am trying to find out what the item index (of the last item selected) is so I can edit the item using the value inputted into the inputbox.
-- No not selecting multiple items.
Thanks, hope it makes sense.
-
May 2nd, 2008, 09:13 AM
#5
Re: [2005] Listview Control Problem
Just to clarify:
The scenario is that a user selects an item in a listview and then clicks a button, which pulls up a dialog box of some sort to allow them to edit the value of the selected item, correct?
If that's the case, then all you have to do is save the selecteditem to in the selectedindexchanged event. If you have multiselect = false on your control, then they can only select one item, which will always be item 0 in the selecteditems collection. So you would have something like:
Code:
Dim M_SelectedItem As Object
Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged
M_SelectedItem = ListView2.SelectedItems(0)
End Sub
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
May 2nd, 2008, 09:15 AM
#6
Re: [2005] Listview Control Problem
If you are going to access selecteditems() in the selectedindexchanged event, then you NEED to check the count first, otherwise you will defenitly end up with an nullreferenceexception.
So you always want to do something like
Code:
If ListView2.SelectedItems.Count <> 0 then
'code here
end if
-
May 2nd, 2008, 09:17 AM
#7
Re: [2005] Listview Control Problem
Nice catch, Kleinma. I'm always bad to forget those little details.
 I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
May 2nd, 2008, 10:35 PM
#8
Thread Starter
Member
Re: [2005] Listview Control Problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|