Solved

Listview

Posted on 1998-08-17
9
358 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.
0
Comment
Question by:test031097
  • 3
  • 3
  • 3
9 Comments
 
LVL 2

Expert Comment

by:cantrell
ID: 1429440
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
 
LVL 2

Expert Comment

by:cantrell
ID: 1429441
Dim trythis As Integer

trythis = List1.ListCount

List1.Selected(trythis - 1) = True


0
 
LVL 2

Expert Comment

by:cantrell
ID: 1429442
Sorry, I hit "submit" first without re-reading your question, but the above should be the answer.
0
 

Author Comment

by:test031097
ID: 1429443
Thanks for your answer, cantrell. But I don't mean a listbox. I mean a LISTVIEW.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 6

Expert Comment

by:anthonyc
ID: 1429444
dim liItem as listitem

set liitem = lvw.selecteditem

'do updating here

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

0
 

Author Comment

by:test031097
ID: 1429445
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
 
LVL 6

Accepted Solution

by:
anthonyc earned 100 total points
ID: 1429446
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
 

Author Comment

by:test031097
ID: 1429447
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
 
LVL 6

Expert Comment

by:anthonyc
ID: 1429448
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now