Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ListView Clearing and Non-Mouse Click Highlighting

Posted on 1998-02-27
3
Medium Priority
?
274 Views
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
      EndProperty
      BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7}
         SubItemIndex    =   1
         Key             =   ""
         Object.Tag             =   ""
         Text            =   "Type"
         Object.Width           =   1676
      EndProperty
   End

Weird huh?  Please help.
0
Comment
Question by:flufgirl
  • 2
3 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 1458131
Can you show the source that you use to do this task?
0
 
LVL 6

Accepted Solution

by:
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()
    ListView1.ListItems.Clear

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!
0
 

Author Comment

by:flufgirl
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?

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 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