Solved

lock listview

Posted on 2009-03-31
5
712 Views
Last Modified: 2013-12-26
I need to be able to lock a ListView control.   In my app I want the user to be able to select an item from the ListView control.  When this happens a series of controls will populate with the properties of that item.  The user will have the option to edit those properties, but I don't want the user to be able to manipulate the ListView while editing is taking place.

If I disable the ListView,  the selection is lost.  Can't see which item is currently being edited and when you re-enable the ListView the selection is lost.

Any help ?
0
Comment
Question by:sidwelle
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Antagony1960
ID: 24030697
If you set the ListView's "HideSelection" property to False the selected row will remain highlighted while the control is disabled.
0
 

Author Comment

by:sidwelle
ID: 24032922
That was simple enough.  Is there any way to change the colors so that you get the same colors if the control has focus or not ?

Thanks
0
 
LVL 11

Accepted Solution

by:
Antagony1960 earned 500 total points
ID: 24035044
I don't think so--nothing simple anyway. It may be possible to subclass the control to do it but that's beyond the scope of my expertise I'm afraid.

I know what you're getting at though: the grey highlighting color is pretty weak so it's difficult to see which item is being edited. Something I usually do is to emphasize the current selection by setting its font to bold in the ItemClick event (assuming it's text). If you're in Report view you can also bold the SubItems via the ListSubItems property. The attached code shows how to do that.

Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)

Static iLastItem As Integer

Dim i As Integer

    With Item

        If .Index = iLastItem Then Exit Sub 'No Change/

        .Bold = True

        For i = 1 To .ListSubItems.Count

            .ListSubItems(i).Bold = True

        Next

    End With

    If iLastItem > 0 Then 'Reset the bolding on the deselected item/

        With ListView1.ListItems(iLastItem)

            .Bold = False

            For i = 1 To .ListSubItems.Count

                .ListSubItems(i).Bold = False

            Next

        End With

    End If

    iLastItem = Item.Index 'Record the current item number/

End Sub

Open in new window

0
 

Author Closing Comment

by:sidwelle
ID: 31564915
I didn't think it was going to be that simple. Thanks for the code. I do have an example that I worked out changing the background color via sub-classing.  Send me an Email if you want the code.
0
 
LVL 11

Expert Comment

by:Antagony1960
ID: 24050839
Glad to have helped. :-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now