• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Listview

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.
0
test031097
Asked:
test031097
  • 3
  • 3
  • 3
1 Solution
 
cantrellCommented:
List1.Selected(1) = True

Replace "List1" with your listbox name, and the "(1)" with the index number of the last item in your listbox.
0
 
cantrellCommented:
Dim trythis As Integer

trythis = List1.ListCount

List1.Selected(trythis - 1) = True


0
 
cantrellCommented:
Sorry, I hit "submit" first without re-reading your question, but the above should be the answer.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
test031097Author Commented:
Thanks for your answer, cantrell. But I don't mean a listbox. I mean a LISTVIEW.
0
 
anthonycCommented:
dim liItem as listitem

set liitem = lvw.selecteditem

'do updating here

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

0
 
test031097Author 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 ********
0
 
anthonycCommented:
well you said updating, NOT deleting.  

Are you using the KEY property?  Save that in a variable before the deleting, then

set lvw.selecteditem = lvw.listitems(szSavedKey)
0
 
test031097Author 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
0
 
anthonycCommented:
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!"

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now