We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Listview

test031097
test031097 asked
on
Medium Priority
376 Views
Last Modified: 2010-07-27
How can I set the last ListIndex and show selected row in a Listview after updating?  I know the selected index before updating the listview. But I'm not able to set the index after updating.
Comment
Watch Question

Commented:
List1.Selected(1) = True

Replace "List1" with your listbox name, and the "(1)" with the index number of the last item in your listbox.

Commented:
Dim trythis As Integer

trythis = List1.ListCount

List1.Selected(trythis - 1) = True


Commented:
Sorry, I hit "submit" first without re-reading your question, but the above should be the answer.

Author

Commented:
Thanks for your answer, cantrell. But I don't mean a listbox. I mean a LISTVIEW.

Commented:
dim liItem as listitem

set liitem = lvw.selecteditem

'do updating here

set lvw.selecteditem = lvw.listitems(liitem.index)

Author

Commented:
Thanks, anthonyc,
this is your propose:

dim liItem as listitem
    set liitem = lvw.selecteditem
    'do updating here

**************
After updating I have to clear the listItems, because I reload the Listview.
The members from iitem (also index) were be deleted by clear listItems.
****************
    set lvw.selecteditem = lvw.listitems(liitem.index)  **** <- it is deleted ********
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, anthonyc. I saved the key in a variable. With help this variable I was able to find the Itemindex.

strKey = LstVwStammdaten.SelectedItem

**************
Delete

*************
For i = 1 To LstVwStammdaten.ListItems.Count
    If "'" & strKey & "'" = LstVwStammdaten.ListItems(i).Key Then
      Exit For
    End If
  Next i

Commented:
ewww.... That code is UGLY!

If you want to find the item index just do this:

dim nIndex as integer
on local error resume next
nIndex = lstVwStammdaten.Listitems(strKey).Index
if nIndex = 0 then msgbox "This item is not in the list!"

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.