Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listview

Posted on 1998-08-17
9
Medium Priority
?
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:test031097
ID: 1429443
Thanks for your answer, cantrell. But I don't mean a listbox. I mean a LISTVIEW.
0
 
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 300 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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