Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

lock listview

Posted on 2009-03-31
5
Medium Priority
?
720 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
[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
  • 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 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

610 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