[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


ListView Clearing and Non-Mouse Click Highlighting

Posted on 1998-02-27
Medium Priority
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
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
  • 2

Expert Comment

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

Accepted Solution

anthonyc earned 800 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no 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…
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…
Suggested Courses

649 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