ListView Clearing and Non-Mouse Click Highlighting

Posted on 1998-02-27
Last Modified: 2012-05-04
Working with the ListView control i have found that if you were to say highlight a selection in a listview control with your mouse, store this index value, clear the listview completely, then put back the information taht was cleared and manually highlight the previously highlighted selection it wont highlight.  
By going through debug i find that it does highlight just after the line that tells it to rehighlight the selection back but once it end's that subroutine the highlighted selection turns off.  
What is causing this and how do i remedy it?
To give you more info i set the listview's property: HideSelection to "FALSE" meaning to maintain its highlighted selection if i somehow loose focus on the listview.
here are my other property selections:

   Begin ComctlLib.ListView ListView1
      Height          =   4335
      Left            =   6480
      TabIndex        =   68
      Top             =   375
      Width           =   2775
      _ExtentX        =   4895
      _ExtentY        =   7646
      View            =   3
      LabelEdit       =   1
      MultiSelect     =   -1  'True
      LabelWrap       =   0   'False
      HideSelection   =   0   'False
      _Version        =   327680
      SmallIcons      =   "ImageList1"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   1
      NumItems        =   2
      BeginProperty ColumnHeader(1) {0713E8C7-850A-101B-AFC0-4210102A8DA7}
         Key             =   ""
         Object.Tag             =   ""
         Text            =   "Name"
         Object.Width           =   2117
      BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7}
         SubItemIndex    =   1
         Key             =   ""
         Object.Tag             =   ""
         Text            =   "Type"
         Object.Width           =   1676

Weird huh?  Please help.
Question by:flufgirl
  • 2

Expert Comment

ID: 1458131
Can you show the source that you use to do this task?

Accepted Solution

anthonyc earned 200 total points
ID: 1458132
Option Explicit
Dim lngHold As Long

Private Sub Command1_Click()
    Dim intI As Integer
    For intI = 1 To 10
        Call ListView1.ListItems.Add(intI, , intI)
    Next intI
End Sub

Private Sub Command2_Click()

End Sub

Private Sub Command3_Click()
    Dim intI As Integer
    For intI = 1 To 10
        Call ListView1.ListItems.Add(intI, , intI)
    Next intI
    Set ListView1.SelectedItem = ListView1.ListItems(lngHold)
End Sub

Private Sub ListView1_Click()
    lngHold = ListView1.SelectedItem.Index
End Sub

This code does what you are sayiing, with proper highlighting!

Author Comment

ID: 1458133
Thanks Anthony but your code works...
And mine still doesnt...go figure....
Your methods are EXACTLY what i implemented into mine originally and i tested your code as a new project and it worked fine.
I also took this portion of the code out of my bigger program and tested it out in a new project and it too works fine, but the weird thing is that it isnt working with the whole program.

I went step by step through the debugger and found that it DOES highlight fine but as soon as it gets to the "End Sub" line it shuts off the highlight.

Are there any programs out there that can trace through your code to see what vb is actually calling (ie. events that i havent put in,etc) or something that i can do to track down what is turning off the highlight?  

PLEASE....i have been looking for 2 months now trying to figure out this error.

Ok, here is what i am trying to do....
I am trying to make it so that if the user double clicks an item in thelistview it will clear the listview and display a new items inside the listview window but following these new items will be the actual selected item.  So instead of storing the index value for the selected item i actually store a "key".
So, when the new items are displayed on screen i check up the key value of what was selected and look through this new list and once i find a match i highlight that item.  Makes sense...but the odd thing is that once i do this it does highlight the item but as soon as it goes past the "End Sub" line (finishing the subroutine) the highlight disappears....
Is this a BUG in VB 5? or am i doing something wrong?


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

19 Experts available now in Live!

Get 1:1 Help Now